Skip to content

Instantly share code, notes, and snippets.

@nabucosound
Last active March 4, 2021 08:42
Show Gist options
  • Save nabucosound/4586383 to your computer and use it in GitHub Desktop.
Save nabucosound/4586383 to your computer and use it in GitHub Desktop.
Vim basic commands cheatsheet. Nothing advanced here, just basic stuff to help my lazy mind remember.

Nabuco's Vim cheatsheet

Normal mode (a.k.a command mode)

i -> insert left of cursor
I -> insert beginning of line
a -> insert right of cursor
A -> insert end of line
o -> new line under current
O -> new line above current

f[char] -> goto next char occurrence in line
F[char] -> goto previous char occurrence in line
; -> repeat last f/F action
. -> repeat last action

caw -> deletes the current word and puts you into Insert mode to change it.
dw -> deletes the current word
D - delete the rest of the line
J -> merge line below

<Ctrl>+F -> page down
<Ctrl>+B -> page up
<Ctrl>+D -> half-page down
<Ctrl>+U -> half-page up
<Ctrl>+E -> line down
<Ctrl>+Y -> line up
zz -> center page to cursor position

gg -> goto line 1
G -> goto last line
[num]G -> goto line [num]

m[char] -> set mark
'[char] -> goto mark line
'. -> goto last edited line
<Ctrl>+O -> jump previous
<Ctrl>+I -> jump next

w -> move to beggining of word forwards
b -> move to beggining of word backwards
e -> move to end of word forwards

) -> paragraph/sentence down
( -> paragraph/sentence up

* -> search for a word forward (cursor on the word)
# -> search for a word backward (cursor on the word)

+ -> next line, first non-whitespace char
- -> previous line, first non-whitespace char

i -> insert in cursor
a -> insert after cursor
o -> insert at line below
O -> insert at line above

p -> paste at line below
P -> paste in line above

>> -> indent
<< -> de-indent

ci" -> change text inside double quotes
ci{ -> change text inside brackets
yi[' or " or ( or {] -> yank text inside specified delimiter
"[char]y -> yank into register
"_d -> delete something without saving it in a register

Block comment: CTRL-V, I, write '#', ESC

<Ctrl>+W <Ctrl>+W -> switch to next splitted window
<Ctrl>+W j -> switch to splitted window below
<Ctrl>+W J -> move splitted window below
<Ctrl>+W k -> switch to splitted window above
<Ctrl>+W K -> move splitted window above
<Ctrl>+W h -> switch to splitted window left
<Ctrl>+W H -> move splitted window left
<Ctrl>+W l -> switch to splitted window right
<Ctrl>+W L -> move splitted window right

Insert mode

Ctrl-w -> delete word

Command-line mode
=================

ZZ -> write buffer and exit (same as :wq!)

:%s/search/replace/gc -> search in whole document, g is for all matches in each line, c to confirm
:%s//replace/ -> replace last searchword
:s/search/replace/ -> replace in visual selection only
:set ic -> set ignorecase
:set scs -> set smartcase
:\c[search text] -> case insensitive search

:tabnew
:e [filename]
:bn -> next buffer
:bd -> close buffer
:e # -> switch buffer

:split [filename]
:vsplit [filename]
:Ctrl-w+s -> split current buffer

:w !sudo tee % -> Save a file you edited in vim without the needed permissions
:noh -> Get rid of current highlighted searched text

:args templates/*/*.html -> Pass required files to apply :argdo command to
:argdo %s/string1/string2/gec | update -> apply command and 'update' only save to modified files.

Vimdiff

do –> Get changes from other window into the current window
dp –> Put the changes from current window into the other window

]c –> Jump to the next change
[c –> Jump to the previous change

zo – open folded text
zc – close folded text

:diffupdate – diff update
:syntax off – syntax off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment