A useful collection of Vim 8.2 quick reference cheat sheets to help you learn vim editor faster.
ā¼/ā¶ Cursor ā½/ā· Target
āāāāāāāāāāāāāā |
āāāāāāāāāāāāāā 0 $ āāāāāāāāāāāāāāā
ā āāāāāāāāāāā ^ fe āāāāāāāāā ā
ā ā āāāāāāāā Fo te āāāāāāāāā ā
ā ā āāāāāāāā To 30| āāāā āā ā
ā ā āā āāāāā ge w āāāā ā āā ā
ā ā āā ā āāā b e āā ā ā āā ā
ā ā āā ā ā āh lā ā ā ā āā ā
ā½ ā½ ā½ā½ ā½ ā½ ā½ā¼ ā¼ā½ ā½ ā½ ā½ ā½ā½ ā½
echo "A cheatsheet from quickref.me"
- SCREEN 1 START
āāā¬āāāāāāāāāā· #!/usr/bin/python
ā ā āāāāā·
ā ā ā print("Hello")
ā ā { } ā¶ print("Vim")
ā ā ā print("!")
ā ā āāā·
ā ā āāāāā¬āāāā· print("Welcome")
G gg H M L k j ā¶ print("to")
ā ā āāā· print("quickref.me")
ā ā print("/vim")
ā ā
ā āāāāāāā·
ā - SCREEN 1 END
āāāāāāāāāāāāāāāā· print("SCREEN 2")
h | j | k | l ā Arrow keys
<C-u> / <C-d> ā Half-page up/down
<C-b> / <C-f> ā Page up/down
b / w ā Previous/Next word
ge / e ā Previous/Next end of word
0 (zero) / $ ā Start/End of line
^ ā Start of line (non-blank)
Fe / fe ā Move to previous/next e
To / to ā Move before/after previous/next o
| / n| ā Go to first/nth column
gg / G ā First/Last line
:n | nG ā Go to line n
} / { ā Next/Previous empty line
H / M / L ā Top/Middle/Bottom screen
zt / zz / zb ā Top/Center/Bottom this line
i / a ā Insert before/after cursor
I / A ā Insert start/end of line
o / O (letter) ā Insert new line below/above
s / S ā Delete char/line and insert
C / cc ā Change to end of/current line
gi ā Insert at last insert point
Esc | <C-[> ā Exit insert mode
:w ā Save
:q ā Close file
:wq | :x | ZZ ā Save and quit
:wqa ā Save and quit all files
:q! | ZQ ā Force quit
:qa ā Close all files
:qa! ā Force quit all files
:w now.txt ā Write to now.txt
:sav new.txt ā Save and edit new.txt
:w !sudo tee % ā Write to readonly file
r ā Replace one character
R ā Enter Replace mode
u / 3u ā Undo changes 1 / 3 times
U ā Undo changes on one line
J ā Join with next line
<C-r> / 5 <C-r> ā Redo changes 1 / 5 times
x ā Delete character (Cut)
p / P ā Paste after/before
xp ā Swap two characters
D ā Delete to end of line (Cut)
dw ā Delete word (Cut)
dd ā Delete line (Cut)
ddp ā Swap two lines
yy ā Yank line (Copy)
"*p | "+p ā Paste from system clipboard
"*y | "+y ā Paste to system clipboard
d | x ā Delete selection (Cut)
s ā Replace selection
y ā Yank selection (Copy)
. ā Repeat last command
; ā Repeat latest f, t, F or T
, ā Repeat latest f, t, F or T reversed
& ā Repeat last :s
@: ā Repeat a command-line command
v ā Enter visual mode
V ā Enter visual line mode
<C-v> ā Enter visual block mode
ggVG ā Select all text
> / < ā Shift text right/left
qi ā Record macro i
q ā Stop recording macro
@i ā Run macro i
7@i ā Run macro i 7 times
@@ ā Repeat last macro
You can save macro for any letters not just i
d ā w
Operator ā Motion
Combine motions to use them
d ā Delete
y ā Yank (copy)
c ā Change (delete then insert)
p ā Paste
= ā Formats code
g~ ā Toggle case
gU ā Uppercase
gu ā Lowercase
> ā Indent right
< ā Indent left
! ā Filter through external program
dd ā Delete current line
dj ā Delete two lines
dw ā Delete to next word
db ā Delete to beginning of word
dfa ā Delete until a char
d/hello ā Delete until hello
cc ā Change current line, synonym with S
yy ā Copy current line
>j ā Indent 2 lines
ggdG ā Delete a complete document
gg=G ā Indent a complete document
ggyG ā Copy a whole document
[count] <operator> <motion>
<operator> [count] <motion>
2dd ā Delete 2 lines
6yy ā Copy 6 lines
d3w ā Delete 3 words
d5j ā Delete 5 lines downwards
>4k ā Indent 4 lines upwards
v ā i / a ā p
Operator ā inner / around ā Text object
Operate with an
p ā Paragraph
w ā Word
W ā WORD (surrounded by whitespace)
s ā Sentence
[ ( { < ā A [], (), or {} block
] ) } > ā A [], (), or {} block
' " ` ā A quoted string
b ā A block [(
B ā A block in [{
t ā A HTML tag block
See :help text-objects
diw ā Delete inner word
dis ā Delete inner sentence
di" ā Delete in quotes
da" ā Delete in quotes (including quotes)
dip ā Delete a paragraph
vi" ā Select inner quotes "..."
va" ā Select quotes "..."
vi[ ā Select inner brackets [...]
va[ ā Select brackets [...]
viw ā Select inner word
vip ā Select inner paragraph
vipip ā Select more paragraph
ciw ā Change inner word
ci" ā Change inner quotes
cit ā Change inner tags (HTML)
cip ā Change inner paragraph
yip ā Yank inner paragraph
yap ā Yank paragraph (including newline)
:e file ā Edit a file in a new buffer
:bn ā Go to the next buffer
:bp ā Go to the previous buffer
:bd ā Remove file from buffer list
:b 5 ā Open buffer #5
:b file ā Go to a buffer by file
:ls ā List all open buffers
:sp file ā Open and split window
:vs file ā Open and vertically split window
:hid ā Hide this buffer
:wn ā Write file and move to next
:tab ba ā Edit all buffers as tabs
<C-w> s ā Split window
<C-w> v ā Split window vertically
<C-w> w ā Switch windows
<C-w> q ā Quit a window
<C-w> T ā Break out into a new tab
<C-w> x ā Swap current with next
<C-w> - / + ā Decrease/Increase height
<C-w> < / > ā Decrease/Increase width
<C-w> | ā Max out the width
<C-w> = ā Equally high and wide
<C-w> h / l ā Go to the left/right window
<C-w> j / k ā Go to the up/down window
:tabe [file] ā Edit file in a new tab
:tabf [file] ā Open if exists in new tab
:tabc ā Close current tab
:tabo ā Close other tabs
:tabs ā List all tabs
:tabr ā Go to first tab
:tabl ā Go to last tab
:tabm 0 ā Move to position 0
:tabn ā Go to next tab
:tabp ā Go to previous tab
gt ā Go to next tab
gT ā Go to previous tab
2gt ā Go to tab number 2
/foo ā Search forward
/foo\c ā Search forward (case insensitive)
?foo ā Search backward
/\v\d+ ā Search with regex
n ā Next matching search pattern
N ā Previous match
* ā Search for current word forward
# ā Search for current word backward
:[range]s/{pattern}/{str}/[flags]
:s/old/new ā Replace first
:s/old/new/g ā Replace all
:s/\vold/new/g ā Replace all with regex
:s/old/new/gc ā replace all (Confirm)
:s/old/new/i ā Ignore case replace first
:2,6s/old/new/g ā Replace between lines 2-6
:%s/{pattern}/{str}/[flags]
:%s/old/new ā Replace first
:%s/old/new/g ā Replace all
:%s/old/new/gc ā Replace all (Confirm)
:%s/old/new/gi ā Replace all (ignore case)
:%s/\vold/new/g ā Replace all with regex
% ā Entire file
ā<,ā> ā Current selection
5 ā Line 5
5,10 ā Lines 5 to 10
$ ā Last line
2,$ ā Lines 2 to Last
. ā Current line
,3 ā Next 3 lines
-3, ā Forward 3 lines
:[range]g/{pattern}/[command]
:g/foo/d ā Delete lines containing foo
:g!/foo/d ā Delete lines not containing foo
:g/^\s*$/d ā Delete all blank lines
:g/foo/t$ ā Copy lines containing foo to EOF
:g/foo/m$ ā Move lines containing foo to EOF
:g/^/m0 ā Reverse a file
:g/^/t. ā Duplicate every line
:[range]v/{pattern}/[command]
:v/foo/d ā Delete lines not containing foo(also :g!/foo/d)
g ā Replace all occurrences
i ā Ignore case
I ā Don't ignore case
c ā Confirm each substitution
& | \0 ā Replace with the whole matched
\1...\9 ā Replace with the group 0-9
\u ā Uppercase next letter
\U ā Uppercase following characters
\l ā Lowercase next letter
\L ā Lowercase following characters
\e ā End of \u, \U, \l and \L
\E ā End of \u, \U, \l and \L
:s/a\|b/xxx\0xxx/g # Modifies "a b" to "xxxaxxx xxxbxxx"
:s/test/\U& file/ # Modifies "test" to "TEST FILE"
:s/\(test\)/\U\1\e file/ # Modifies "test" to "TEST file"
:s/\v([abc])([efg])/\2\1/g # Modifies "af fa bg" to "fa fa gb"
:s/\v\w+/\u\0/g # Modifies "bla bla" to "Bla Bla"
:s/\v([ab])|([cd])/\1x/g # Modifies "a b c d" to "ax bx x x"
:%s/.*/\L&/ # Modifies "HTML" to "html"
:s/\v<(.)(\w*)/\u\1\L\2/g # Make every first letter of a word uppercase
:%s/^\(.*\)\n\1/\1/ # Remove duplicate lines
:%s/<\/\=\(\w\+\)\>/\U&/g # Convert HTML-Tags to uppercase
:g/^pattern/s/$/mytext # Find and append text to the end
:g/pattern/norm! @i # Run a macro on matching lines
/^\(.*\)\(\r\?\n\1\)\+$ # View the duplicates lines
/\v^(.*)(\r?\n\1)+$ # View the duplicates lines (very magic)
:v/./,/./-j # Compress blank lines into a blank line
:g/<p1>/,/<p2>/d # Delete inclusively from <p1> to <p2>
$ vimdiff file1 file2 [file3]
$ vim -d file1 file2 [file3]
:[range]diffget [bufspec]
:[range]diffput [bufspec]
do / :diffget ā Obtain (get) difference
dp / :diffput ā Put difference
:dif ā Re-scan differences
:diffo ā Switch off diff mode
:1,$+1diffget ā Get all differences
ZQ ā Quit without changes
See:
zo / zO ā Open
zc / zC ā Close
za / zA ā Toggle
zv ā Open folds for this line
zM ā Close all
zR ā Open all
zm ā Fold more (foldlevel += 1)
zr ā Fold less (foldlevel -= 1)
zx ā Update folds
]c ā Next difference
[c ā Previous difference
vU ā Uppercase character
vu ā Lowercase character
~ ā Toggle case character
viw U ā Uppercase word
viw u ā Lowercase word
viw ~ ā Toggle case word
VU / gUU ā Uppercase line
Vu / guu ā Lowercase line
V~ / g~~ ā Toggle case line
gggUG ā Uppercase all text
ggguG ā Lowercase all text
ggg~G ā Toggle case all text
<C-o> ā Go back to previous
<C-i> ā Go forward
gf ā Go to file in cursor
ga ā Display hex, ascii value
:h ā Help open help view
:edit! ā Reload current file
:2,8m0 ā Move lines 2-8 to 0
:noh ā Clear search highlights
:sort ā Sort lines
:ter ā Open a terminal window
:set paste ā Enable Insert Paste sub-mode
:set nopaste ā disable Insert Paste sub-mode
:cq ā Exiting with an error(aborting Git)
% ā Nearest/matching {[()]}
[( | [{ ā Previous ( or {
]) | ]{ ā Next ) or }
[m ā Previous method start
[M ā Previous method end
<C-a> ā Increase number
<C-x> ā Decrease number
:tag Classname ā Jump to first definition of Classname
<C-]> ā Jump to definition
g] ā See all definitions
<C-t> ā Go back to last tag
<C-o> <C-i> ā Back/forward
:tselect Classname ā Find definitions of Classname
:tjump Classname ā Find definitions of Classname (auto-select 1st)
:ce 8 ā Center lines between 8 columns
:ri 4 ā Right-align lines at 4 columns
:le ā Left-align lines
See :help formatting
`^ ā Last position of cursor in insert mode
`. ā Last change in current buffer
`" ā Last exited current buffer
`0 ā In last file edited
'' ā Back to line in current buffer where jumped from
`` ā Back to position in current buffer where jumped from
`[ ā To beginning of previously changed or yanked text
`] ā To end of previously changed or yanked text
`< ā To beginning of last visual selection
`> ā To end of last visual selection
ma ā Mark this cursor position as a
`a ā Jump to the cursor position a
'a ā Jump to the beginning of the line with position a
d'a ā Delete from current line to line of mark a
d`a ā Delete from current position to position of mark a
c'a ā Change text from current line to line of a
y`a ā Yank text from current position to position of a
:marks ā List all current marks
:delm a ā Delete mark a
:delm a-d ā Delete marks a, b, c, d
:delm abc ā Delete marks a, b, c
<C-r> = 7*7 ā Shows the result
<C-r> = 10/2 ā Shows the result
Do this in INSERT mode
:!<shell> ā Interpret Shell Command
:r!<shell> ā Read in output of shell
:r!date ā Insert date
:!!date ā Replace current line with date
<C-r><C-w> ā Insert current word into the command line
<C-r>" ā Paste from " register
<C-x><C-f> ā Auto-completion of path in insert mode
Remove duplicate lines
:sort | %!uniq -u
To number the lines in the file
:%!cat -n
Copy whole doc to clipboard
:%w !pbcopy # Mac OS X
:%w !xclip -i -sel c # GNU/Linux
:%w !xsel -i -b # GNU/Linux