Folds
zato toggle current foldzmto close,zrto open
Windows
from windows
A buffer is the in-memory text of a file.
A window is a viewport on a buffer.
A tab page is a collection of windows.
- Opening:
CTRL-Wandv(vert),s(split/duplicate),n(horiz) - Closing:
CTRL-Wandq(quit),c(close) - Moving cursor:
CTRL-Wand up, down, left, right - Moving windows:
CTRL-W CTRL-Omake window the only(maximize)
Plugin mappings
- sensible:
CTRL-uin insert mode: delete backwards, for real - sneak:
sorSand then two letters for faster jumping,;to repeat - table-mode:
<leader>tmto toggle,<leader>trto realign,SHIFT-jklöto jump table cells - multiple cursors:
CTRL-nto select word,CTRL-pfor undo,CTRL-xto skip the current one
Settings in vimrc
:::vim
" vimrc
" Remember last position
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"")
\ <= line("$") | exe "normal! g'\"" | endif
endif
" set pyton3
let g:python3_host_prog = '/usr/bin/python3'
" highlighting
hi Search cterm=black ctermfg=white ctermbg=red
" German keyboard layout
nnoremap j h
nnoremap k j
nnoremap l k
nnoremap ö l
Movement
see scroll
- scroll line for line:
CTRL-e(up)CTRL-y(down) - scroll window half a screen:
CTRL-u(up)CTRL-d(down) - scroll full windows:
SHIFT-UPandSHITFT-DOWN - move line to top of window:
z-ENTER - Jump back
CTRL-o(andCTRL-ifor forward) - Move to last position
''or use double backticks - delete(in insert move): like in
fish:
CTRL-kto end,CTRL-uto start,CTRL-wto delete word CTRL-hfor backspace,CTRL-jfor enter- run single command in insert mode:
CTRL-O - deleting(normal)(swap
aforifor inner):
swapcford: deletng, forv: visual select, fory: ‘copy’ciw: change in wordcis: change in sentencecibanddiB: change()and{}blockscip: change in paragraphcit: change in tags(html)
Dto delete from cursor to end of line- move by whole words(no whitespace):
W (),{}: jump sentences, paragraphsH M L: move to top, middle, bottom of viewport- marks:
m(register): mark point (here:x)'x(single quote): jump to point(my mapping, default is backtick)
- pasting:
pafter cursor,Pbefore cursor CTRL-r-xto insert from registerxwhile in insert mode
Very useful
- wrap lines
visual select and then
gq - use previous selection
gvfor selecting previous visual selectiongito go into insert mode in previous position oin visual mode jumps to other end of selection=to reformat textciw''P: enclose in quotes
General
- get out of “completion mode” / resume flow control
CTRL-q - save and quit vim
ZZ, to only quit:ZQ, to write all files and quit::xa - escape
CTRL-c - indents
use
CTRL-i(indent) andCTRL-d(remove indent) in insert move,
use>and<in visual mode(once) and in normal(press twice) - jump to line
[line nr], G - recording
q [letter]to start recording
qto stop,@ [letter]to play back - parenthesis
([{jumping% - manipulate multiple lines
use visual selection and then
:norm <command>, e.g.:'<,'>norm A,
or block(CTRL-v) select and then$A<text>to append to all lines - numbers
CTRL-aandCTRL-xincrement and decrement - netrw
use
CTRL-oandCTRL-ito switch, use%to create a file - replacing/‘substituting’
setincsearchand then search/oldstring, replace with%s//newstring/
:s/oldstring/newstring(only once)
:s/oldstring/newstring/gic: global, ignore case and confirm each:[startline],[endline]s/oldstring/newstring/greplace only between specified lines
&: **repeat last subsitution - writing
visual selection only writes the selected part
wr:rloads file, can be combined with!<command> - windows
CTRL-W CTRL-Wswitch windows - neat
CTRL-X [o p n]auto-complete and more~toggle upper/lowercase, in visual mode:uandUfor lower/uppercasing:bro olbrowse oldfiles
- dictionary
usezgon a word to add it to dictionary
located in~/<vimdir>/spell/en.utf-8.add - fix encoding
:set bomb
:set fileencoding(s)=utf-8
:w - whitespace
%lefor removing indents
g/^$/dfor removing blank lines
:%s/\s\+$//for removing trailing whitespace - centering
:ce columns: center with columns width - abbreviations
ab lw Long word: expand ’lw’ to “Long word”una lw: unset the abbreviation- tabs to spaces
:retab
Mappings
::vim
:nmap - Display normal mode maps
:imap - Display insert mode maps
:vmap - Display visual and select mode maps
:smap - Display select mode maps
:xmap - Display visual mode maps
:cmap - Display command-line mode maps
:omap - Display operator pending mode maps
Todo
- Use registers more often
- Use ci{ and the like more often
- Jump by
sandfinstead of hjkl - Use
CTRL-handCTRL-jfor backspace and enter - map NOP to unused extension mappings for uncluttering :map and no surprises
- Explain d/D, y/Y, c/C, p/P, b/B, i/I, … in various modes