Vim Editor

Describes some standard and custom keyboard mappings used in Vim. Most of these commands apply to NeoVim as well.

Vim Common

Rtext        Begin replace with text
G            End of file
gg           Start of file (or use 1G)
ZZ           Write and quit file
J            Join 2 lines
j^  h        Move down to first character on line
j$  l        Move down to last character on line
%            Find current parens match (matching bracket, brace)
d^           Delete to begin of line
E            Move to end of word ignore punc
W            Move to begin of word ignore punc
c-g          Filename and line number
c-k          Kill text to end of line
Q            Exit if in ex mode
q:           Command history (c-c x2 exit)
.            Repeat last change
u  U         Undo last command, restore last changed line
^r           Redo last undo

Ex Common

:ls          List buffers, % cur buffer, # alt buffer, a is active
:b N         Open buffer number N (as shown in ls)
:sb N        Horizontal split buffer number N (as shown in ls)
:vert sb N   Verical split buffer number N
:tabe N      Open buffer number N in new tab
:bn          Go to the next buffer
:bp          Go to the previous buffer
:bd          Unload (delete) current buffer
:bd N        Unload buffer number N (as shown in ls)
:noh         Disable highlighted
:set num     Show line numbers
:set list    Show tabs/end of lines
:new         Open a new buffer
:f           File status
:n           Goto line num n
:+5num       Print line number at +5 lines
:/pat/num    Print line number at pattern

Indentation

c-t          Indent one level
c-d          Indent back one level
0 c-d        Indent reset to 0
<<           Shift left
>>           Shift right
<%           Shift left to parens
c-6          Switch between active a and # alt buffer

Visual Mode

v            Visual mode by character
V            Visual mode by lines
c-v          Visual mode by blocks
"ay          Save selected text to buffer a

Memory Buffers

"a           Buffer named a
"2           Buffer 2 has previous contents
"+           System buffer
"a4yy        Yank 4 lines into buffer a
"A2yy        Yank 2 more lines into a
"aP          Put buffer a before cursor
"2p          Put buffer a after cursor
"1p.u.u.     Increment through numbered buffers
"+y          Yank to system buffer
"+y3j        Yank next 3 lines to system buffer

Putting Text

p            Put text after cursor
P            Put text before cursor
]p           Put text after cursor, match indentation
[p           Put text before cursor, match indentation

Marking Position

mx           Mark current position as x
`x           Move to mark x
'x           Move to start of line with x
``           Return to previous mark
''           Like above but start of line
:marks       Show bookmarks

Screen Position

zt  z<RET>   Position top of screen
z.           Position middle
zb  z-       Position bottom
c-d          Down 1/2 screen
c-f          Down full screen
c-u          Up 1/2 screen
c-b          Up full screen (back)
c-e          One more line at bottom (extra)
c-y          One more line top of screen

Character Searching

fx           Search forward x on line
Fx           Search backward x on line
tx           Search forward before x
Fx           Search backward to after x
;            Repeat current line search
,            Reverse current line search

Substitutions

:%s/ [ ]*$//      Delete all whitespace at end of each line
:%s/^[a-z]/- &/   Substitution First character with - char
:g/pat/d          Delete lines with pattern using global command
:g/^$/d           Delete blank lines using global command
:g/pat/norm f;x   On lines with pattern, search for ; and delete
:g/pat/norm "aP   On lines with pattern, put buffer a before cursor

Mappings

:map              Show current mapped keys
:map!             Show insert mode mapped keys
:map! DD *DEL*    Creates map on insert mode that inserts *DEL* for DD
:map h j^         Create a map for h that goes down one line, start of line
:unmap h          Remove map for key h