Folds
za
to toggle current foldzm
to close,zr
to 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-W
andv
(vert),s
(split/duplicate),n
(horiz) - Closing:
CTRL-W
andq
(quit),c
(close) - Moving cursor:
CTRL-W
and up, down, left, right - Moving windows:
CTRL-W CTRL-O
make window the only(maximize)
Plugin mappings
- sensible:
CTRL-u
in insert mode: delete backwards, for real - sneak:
s
orS
and then two letters for faster jumping,;
to repeat - table-mode:
<leader>tm
to toggle,<leader>tr
to realign,SHIFT-jklö
to jump table cells - multiple cursors:
CTRL-n
to select word,CTRL-p
for undo,CTRL-x
to 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-UP
andSHITFT-DOWN
- move line to top of window:
z-ENTER
- Jump back
CTRL-o
(andCTRL-i
for forward) - Move to last position
''
or use double backticks - delete(in insert move): like in
fish
:
CTRL-k
to end,CTRL-u
to start,CTRL-w
to delete word CTRL-h
for backspace,CTRL-j
for enter- run single command in insert mode:
CTRL-O
- deleting(normal)(swap
a
fori
for inner):
swapc
ford
: deletng, forv
: visual select, fory
: ‘copy’ciw
: change in wordcis
: change in sentencecib
anddiB
: change()
and{}
blockscip
: change in paragraphcit
: change in tags(html)
D
to 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:
p
after cursor,P
before cursor CTRL-r-x
to insert from registerx
while in insert mode
Very useful
- wrap lines
visual select and then
gq
- use previous selection
gv
for selecting previous visual selectiongi
to go into insert mode in previous position o
in 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
q
to 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-a
andCTRL-x
increment and decrement - netrw
use
CTRL-o
andCTRL-i
to switch, use%
to create a file - replacing/‘substituting’
setincsearch
and 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/g
replace only between specified lines
&
: **repeat last subsitution - writing
visual selection only writes the selected part
wr:r
loads file, can be combined with!<command>
- windows
CTRL-W CTRL-W
switch windows - neat
CTRL-X [o p n]
auto-complete and more~
toggle upper/lowercase, in visual mode:u
andU
for lower/uppercasing:bro ol
browse oldfiles
- dictionary
usezg
on 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
%le
for removing indents
g/^$/d
for 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
s
andf
instead of hjkl - Use
CTRL-h
andCTRL-j
for 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