Cheatsheet for the editor VIM
Table of Contents
Vim Modes
esc
- Normal Modesi
- Insert Modev
- Visual ModeR
- Replace Mode
Colon commands
:w
- write/save filew <filename>
- white to provided filename:q
- quit vim:q!
- force quit vim (changes will be discarded):set number
- shows line numbers:set nonumber
- hides line numbers
Moving Around
h
orarrow left
- move the cursor one character to the leftl
orarrow right
- move the cursor one character to the rightj
orarrow down
- move the cursor one line downk
orarrow up
- move the cursor one line up0
- move the cursor to the beginning of the line$
- move the cursor to the end of the linew
- move the cursor one word forwardb
- move the cursor one word backgg
- move to the beginning of the file (line 1)G
- move to the end of the line (last line)o
- adds an empty line below the cursor, moves the cursor to that line, enters edit modeO
- adds an empty line above the cursor, moves the cursor to that line, enters edit mode
Deleting things
de
- delete from where the cursor is until the end of the current worddw
- delete to next wordd2w
- delete two words from cursord$
orD
- delete to the end of the line from where the cursor isdd
- delete the whole line (cut)x
- delete characters
- delete character and insertS
- delete line and insertC
- delete until the end of line and insert
Editing things
a
- append enter insert mode one char right of cursorA
- append from end of liner
- replace one character on cursorR
- enter replace modeu
- undo changesgU<direction>
- uppercase character in chosen directiongu<direction
- lowercase character in chosen direction
Copy and pasting
dd
- cut the whole lined<direction>
- cut character in chosen directionyy
- copy the whole liney<direction>
- copy the character in chosen directionp
- paste contentP
- paste before cursor"*p
- paste from system clipboard"*y
- copy to system clipboard
Search for things
:?<term>
- searches for that term from the cursor down:/<term>
- searches for that term from the cursor up*
- search whole word from the cursor down#
- search whole word from the cursor upn
- go to the next searched termN
- go to the previous searched term
Replacing things
:s/<search term>/<replace term>
- search for and replace term in the current line and replace:%s/<search term>/<replace term>
- search for and replace term in the whole file:{from, to}s/<search term>/<replace term>
- search for and replace term from linefrom
to lineto
Flags that you can use
g
- search and replace globaly in the filei
- ignore case when searchingc
- ask confirmation before replacing
Useful search/replace commands
:2,10s/^/#/
- comments lines from 2 to 10:2,10/^#/
- uncomment lines from 2 to 10:%s/\s\+$//e
- remove trailing white space at the end of each line
Tabs
vim -p <filename> <filename>
open file in a separate tab:tabnew
- opens a new tab page with an empty window:tabc
- close current tab:tabc!
- force close current tab discarding changestabn
- move to next tabtabN
- move to previous tab
Webmentions
0 Like 0 Comment