ikwyl6 Vim Cheat Sheet

General

[count][command][motion] - General formation of commands

Text Objects

iw - inside a word
aw - around a word
ip - inside a paragraph
aw - around a paragraph
i{ - inside a {} block or [] () '' "" ``
a{ - around a {} block or [] () '' "" ``

Files

:e file - edit file
:e! - re-edit, dischard changes
:e + file - edit file, starting at end of file
:e +# - edit file, starting at line #
:e # - edit alternate file (?)
:w [file] - write file (current file if no name given)
:w! file - overwrite file
:w >>file - append file (current file if no name given)
:23,45w snippet.txt - Write the contents of the lines numbered 23 through 45 to a new file named snippet.txt
:r file - read file after line
:r !program - read program output
:f or ^G - show file name, total number of lines and percentage location within file
:q or :q! - quit or quit without saving
:x or ZZ - Save (if there are changes) and quit
ZQ - Quit without checking for changes

Editing

i or I - insert before cursor or before the first non-blank in the line
a or A - append text after cursor or end of line
o or O - enter insert mode but insert line after current one or before current line
r[char] - replace single character with letter [char]
[#]r[char] - replace number of characters [#] with character [char]. Example: 3rf
R - enter replace mode
s - delete character under cursor and go into insert mode
x or X - delete character under cursor or before cursor
c or #c - change a character or change three characters 3c
cc or S or #cc or C - change/replace whole line cc/S or remove and change # lines starting from cursor or change/replace to end of lineC
ciw - change word under cursor
caw - change around word (including trailing space)
cw - change word under cursor
ci" - change inside ""
d - delete
dw or d#w - delete word or delete # of words
diw - Delete inside word
daw - Delete word and trailing space
di" or di' or di) or di} - Delete inside double quotes, single quotes, parenthese, or curly braces
dd or #dd - delete a line (and copy it to system register), delete # lines
d$ or D - delete from cursor up to end of line
:5,25d - delete lines 5-25
:.m 12 - move current line after line 12
:5,7m 21 - move lines 5-7 after line 21
ddp or ddkP - move line down or move line up
u or U - undo last change or restore (undo all changes to) current line
:undolist - list your possible undo changes using u
J - join current and below line with space in between
gJ - join current and below line with no space between
:78,83join - join range of lines together

Moving Around

h or #h - Move one character to the the left or # characters to the left
j or #j - Move one line down or # lines down. #j is very useful when :relativenumber is enabled
k or #k - Move one line up or # lines up. #j is very useful when :relativenumber is enabled
l or #l - Move one character to the right or # characters to the right
ctrl-d or ctrl-u - Move down 1/2 page or move up 1/2 page
ctrl-f or ctrl-b - Move down full page or move up full page
H or M or L - Move to top H, middle M or bottom of screen L
w or W - jump ahead to start of next word or space-separated Word
e or E - jump ahead to end of next word or space-separated word
b or B - jump backward to start of previous word
gg or [[ or G or ]] or #G - Jump to 1st line of file gg or [[, last line of file G or ]], or #th-line of file
g; or g, - Move back to previously / newer changed line (older/newer position in change list). Similar command as CTRL-O and CTRL-I (jump list)
`` - Jump between the last two changed positions in change list
#% - Move to the # % of file. 25% would move to the 25% percent of file
#| - Move to # column in line
[Enter] or + - Move to the next non-blank character on line
- - move to the previous line at the first non-blank character
:# - move to line # where # is a number.
% - find matching ( ) or {
/[chars] - search for a string below cursor
?[chars] - search for a string above cursor
n or N - search for next or previous search occurence using / or ?. Or keep hitting / or ? and [Enter] will do same thing
( or ) or { or } - move to beginning or end of sentence or beginning/end of paragraph (or next blank line)
0 or ^ or $ or g_ - go to beginning of line, start of first non-blank character in line (or underscore _), end of line, or last non-blank character in line
f{char} or F{char} or t{char} or T{char} - jump to next f or previous F character, jump to next t or previous T character but behind one character
, or ; - using f or t commands above, repeat in the command direction or previous direction
zt zz zb - orient screen so line is at (top|center|bottom) of screen

Marks

:marks - list all marks in current file and all files. Text in blue will be marks for current buffer
ma - create mark 'a' at current cursor location
'a - jump to line of mark 'a' (first non-blank character of line)
`a - jump to position, line, and column of mark 'a'
d'a - delete from current line to line of mark 'a'
d`a - delete from current current position to position of mark 'a'
'' - jump back to line in current buffer where last jumped from

Repeating Commands

. or ctrl-r or #. - Repeat last command performed or repeat last command # times
#{command} - Repeat command # times

Searching for text

:/search - search for 'search'
:/search/d - search and delete the text that was found
:/search/y - search and yank the text that was found
:/search1/,/search2/d - search and delete lines with multiple patterns
:%s/target/=@0/g - replace target with what is yanked
:%s/search/replace/g - search and replace over whole file (%)
:g/pattern/d - delete all lines with pattern
:v/pattern/d - delete all lines that do not match pattern

Visual Mode

v - enter visual mode
V - enter visual mode highlighting the current line
viw - visually select word without spaces
vaw - visually select word with trailing space
vi[ - visully select inside next occurence of [
gv - reselect the last visual selection

Moving Visually Selected Text

:le 10 - takes the visually selected text and adds 10 spaces to the left of this selected text starting from beginning of line

Copy, Cut and Paste / Registers

yy or Y - Copy/Yank current line
5yy - Copy/Yank current line and 5 lines below it
y$ - Copy/yank from current cursor to end of line
y^ - Copy/yank from current cursor to start of line
yw - Copy/yank to the start of the next work
:#y - copy/yank line number #
:#copy or :#t. - copies the line specified and pastes it to the line below
:-10t. - copy 10 lines above the current line and paste it below the current line
:10,20t. - copy lines 10 to 20 and paste them below
:t20 - copy the current line and paste it below line 20
p or P - paste before cursor or after cursor
"ap - paste from register a
"+p - paste from the system clipboard
".p - paste from last inserted text
"0-9p - paste from delete history
"xy - yank into register x
"xd - delete into register x
:reg[isters] - list registers and their contents
]p - paste line with right indent
:.!program - replace line with program output

Split Windows

:sp[lit] [file] - split window horizontally opening [file]
:vs[plit] [file] - split window vertically opening [file]
Ctrl+ww - switch to other split window
Ctrl+w[dir] - move to split window using direction ([dir] can be hjkl or arrow keys)

Folds

zf - create fold at cursor position
zf{motion} OR {Visual}zf - create a fold. Example: zf#j - create a folder from cursor down # lines. zfgg - create fold from cursor to top of file. zfG - create fold from cursor to bottom of file
zf/string - create a fold from the cursor position to the first instance of the search string
zj or zk - move downwards or upwards
zd or zD - delete fold marker under cursor (or recursively zD)
za - toggle fold at cursor location
zF - create a fold for [count] lines
:{range}fo[ld] - create a fold for {range}
zo or zO - open fold (zO) recursively
zc or zC - close one fold under the cursor recursively
za or zA - open or close a fold recursively (zA)
zv - view cursor line
zm or zM - increase folding: Subtract one from 'foldlevel'
zr or zR - reduce folding: Add one to 'foldlevel'. zR Decreases foldlevel to zero and opens all folds
zE - delete all folds
:{range}foldo[pen][!] - open folds in {range}. [!] all folds are
:{range}foldc[lose][!] - close folds in {range}. [!] all folds
zn or zN - all folds will be open
zi - invert 'foldenable'
[z or ]z - move to the start or the end of the current open fold

Tabs

$ vim file1 file2 ... -p - Open each file in a tab
:argdo tabe - Open all files in their own tab
:tabnew [file] or :tabe[dit] [file] - Create a new tab [with file]
:tabc[lose]- Close current tab
:tab help tabs - create new help window about tabs in a new tab
Ctrl-Shift-[Up/Dn]Rotate between tabs
Ctrl-w TMove window to a new tab
:args - Print the argument list
:ls - List buffers
:n - edit next file in buffer
:p - edit previous file in buffer

Links

Cheat sheet: sk3pp3r cheat-sheet-pdf
:h index or vimhelp.org vim index
vim TOC
I Read The Entire Neovim User Manual - TJ DeVries