Vim Memo (summarizing the Getting Started part of the User's Manual)

Vim terminology

Standard word Vim term
save write
cut delete
copy yank
paste put
overwrite replace

Miscellaneous commands

Quit (w/o writing) :qa[ll]! / :quita[ll]!  
Write all and exit :wqa[ll] / :xa[ll]  
Abort command   CTRL-C
Undo :u[ndo] u
Redo :red[o] CTRL-R
Help :h[elp] <topic> <F1>
Go to tag definition   CTRL-]
Go back :po[p] CTRL-T / CTRL-O
Set an on/off option :set [no]<option> :set <option>? : current value
Set an option :set <option>=<value>  
List of options :options  
Syntax highlighting :syntax on/off :colorscheme : various schemes

Changing modes

Insert mode (before cursor) i I: at the beginning of line
Insert mode (after cursor) a A: at the end of line
Replace mode R  
Visual mode v V: select lines; CTRL-V: select blocks

Files and buffers

Edit (open) file :e[dit] <file>  
Write file :w[rite] :w[rite] >> <file> : append to file
Close file (w/o writing) :q[uit]! ZQ
Write and close file :wq / :x[it] / :exi[t] ZZ
Save as :saveas <filename>  
Edit next file :n[ext] :wn[ext] : write and edit next file
Edit previous file :prev[ious] :wp[revious] : write and edit prev file
Edig the alternate file CTRL-^  
Change buffer :b[uffer] <buffer>  
Next buffer :bn[ext]  
List buffers :ls / :buffers / :files  

Moving around

Left / Down / Up / Right h / j / k / l  
Scroll forward (down) one page CTRL-F CTRL-D: half page; CTRL-E: one line
Scroll backward (up) one page CTRL-B CTRL-U: half page; CTRL-Y: one line
To beginning of next word w W: same with whitespace-boundaries
To beginning of this word b B: same with whitespace-boundaries
To the end of this word e E: same with whitespace-boundaries
To the end of last word ge gE: same with whitespace-boundaries
To beginning of line 0 ^: ignoring whitespace characters
To end of line $  
To char <c> in current line f + <c> F: backwards (;: next, ,: previous)
To char before <c> in current line t + <c> T: backwards (;: next, ,: previous)
Change side (in visual mode) o  
Jump to matching parenthesis %  
Jump to beginning of file gg  
Jump to the <n>-th line <n> + G  
Jump to the end of file G  
Jump to top/middle/bottom of the window H / M / L  
Show current line at top/middle/bottom zt / zz / zb  
Set a mark to the letter <c> m + <c> use uppercase letters for global marks
Jump to a mark at letter <c> ` + <c> ' + <c>: the beginning of that line
Show all marks :marks :marks <cde> : show only marks c,d,e
Jump to last change `. `^: to last insertion
Back from a jump ``  

Windows

New file in new window (horizontal) :new CTRL-W [CTRL-]n
New file in new window (vertical) :vne[w]  
Split window (horizontal) :sp[lit] CTRL-W [CTRL-]s
Split window (vertical) :vs[plit] CTRL-W [CTRL-]v
Edit file in new window (horizontal) :new <file> / :sp[lit] <file>  
Edit file in new window (vertical) :vne[w] <file> / :vs[plit] <file>  
Enlarge/shrink window by N lines :res[ize] +N / :res[ize] -N [N] CTRL-W +/-
Change to "the other" window   CTRL-W [CTRL-]w
Change to the (left/bottom/top/right) window   CTRL-W h/j/k/l
Close window :clo[se] CTRL-W c
Close all other windows :on[ly] CTRL-W [CTRL-]o

Tabs

Edit file in new tab :tabe[dit] <file> / :tabnew <file>  
Edit same buffer in new tab :tab split  
Close current tab :tabc[lose]  
Close all other tabs :tab[only]  
Go to next tab :tabn[ext] gt
Go to previous tab :tabp[revious] / :tabN[ext] gT
Go to first tab :tabr[ewind] / :tabfir[st]  
Go to last tab :tabl[ast]  
Move tab N spaces :tabm[ove] +N / :tabm[ove] -N  
Run command in new tab :tab <command>  

Editing

Delete d + <movement>  
Delete line dd D: just right from cursor (= d$)
Change (delete + insert mode) c + <movement> C: (= Da)
Change line cc C: just right from cursor (= c$)
Delete current char x (= dl) X: backwards (= dh)
Substitute a char s (= cl) S: (= cc)
Replace current char with <c> r <c>  
Open line below o O: open row above
Yank y + <movement>  
Yank line yy / Y  
Put p P: before cursor
Select register for next d/y/p " + <register> (yank always uses 0, as well)
Show registers :reg[isters] / :di[splay]  
Change case ~  
  • transpose chars: xp
  • transpose lines: ddp
  • duplicate line: yyp

Registers

default "
yank 0
black hole _
clipboard +
primary clipboard *
expression =
current filename %
alternate filename #
last insertion .
last Ex command :
last search /

Search & replace

Search <string> / <string> ?: backwards
Search word under cursor *  
Next match n N: previous
Substitute :[<range>]s[ubstitute]/[<old>]/<new>[/<flags>] &: repeat (no flags)
  • <range> is the current line by default
  • <old> is the last search by default
  • flags: g (global), c (confirm), n (only count), & (same flags as before)
  • confirm mode: y/n (yes/no), q (quit), l (yes + quit), a (all); C-e/C-y (scroll up/down)

Ranges

  • % means the whole file
  • a,b for lines a-b (. is the current line, 0 the zeroth, 1 the first, $ the last)
  • these can be regexps, e.g. start,/end/, or marks, e.g. 't,'b
  • can have offsets, e.g. start/+1,/end-1
  • visual mode selections also specify ranges (o: changes active end [O: other corner for blocks])

Automatization

Record macro in <register> q + <register> [stop: q, use uppercase register to append]
Play macro in <register> @ + <register> [after that: @@]
Repeat last command .
Repeat <command> <n> times <n> + <command>
Repeat last Ex command @: [after that: @@]
Execute commands for range :[<range>] normal <commands>
Execute commands for matches :[<range>] global[!] <pattern> <commands>

Author: Peter Salvi

Created: 2019-03-29 Fri 11:37

Emacs 26.1 (Org mode 8.2.4)

Validate