Some Useful VIM Shortcuts


A list of basic VIM commands to be productive

When I was learning VIM I was writing down commands and motions from different tutorials and tried to use them. I ended up using a sub-set of these which work for me. I am listing this sub-set which seems to be most useful.

Editing files

:e filename - edit file

:w filename - save file

:q - quit

:qa! - quit all (! means forced)

:e! - reload current file

ZQ - don’t save and quit

ZZ - save and quit

Moving around the document

h j k l - moving around the document

CTRL-e CTRL-y - moving document up or down without moving cursor

H M L - jumping to top, middle or bottom of current window

gg - beginning of file

G - end of file

XXG - move to line XX (XX is a number)

`. - jump to last changed line

* or # - searches next or previous word under cursor

? or / - searching backward or forward in document

n or N - next or previous word in search

m {a..z} - mark position with a letter in document

` {a..z} - jump to the position with letter

' {a..z} - jump to the position with letter but start at first non-blank character on the line


i or I and a or A - insert mode before or after cursor. Capital ‘I’ start of line, capital ‘A’ end of line

o - new line

O - new line above

x or X - delete character under or before cursor in normal mode

XXx - delete XX characters in normal mode

y-<motion> - yank text

yy - yank whole line

p - paste yanked text

c-<motion> - cut text

d-<motion> - delete text

dX-<motion> - delete X of

u - undo last change

CTRL-r - redo last change (undo had to be executed before)

:%s/old/new/gc - substitute old for new, ‘c’ stand for confirmation

" {a..z} - access register (e.g. "ay - y ank to register a)

CTRL-r {a..z} - convenience to insert text from register {a..z} in normal mode

:reg - shows content of all registers


^ - start of line (SHIFT-6 usually)

$ - end of line (SHIFT-4 usually)

w or e - forward motion at start or end of a word

b - backward movement cursor at start of a word

W - to next word which starts after a blank space

$ - till the end of line

^ - till the start of line

t-<char> or T-<char> - forward or backward till the char (exclusive)

f-<char> or F-<char> - forward or backward till the char (inclusive)

; or , - repeat f or t forward or backward

e - end of next word

a - ‘around’ (e.g. daw - delete ‘around’ word)

i - inside (e.g. ci" - cut everything inside brackets ")

D - delete till the end of line

C - cut till end of line

Y - yank till end of line

Working with multiple files (advanced)

:vs filename - vertical split open filename

:sp filename - horizontal split open filename

CTRL-w w - switch to next window

CTRL-w s - split window vertically

CTRL-w v - split windows horizontally

CTRL-w Q - close tab or split

CTRL-w o - close everything except the current window

CTRL-w r - swap window screen

:vertical res - resize splits to res

:Te or :Texplore - file explore in new tab

:tabm X - move current tab to X-th position

:tabn - go to next tab

:tabp - go to previous tab

:tabe filename - open file in tab

:tabonly - close other tabs

gt or gT - move forward or backward between tabs

:bd - close current tab and delete buffer


. - repeat last command

v or V - visual or visual line mode (in visual mode you can do commands lile yank or delete)

CTRL-v - visual block mode

:Explore - open file explore

Multiline edit in visual block mode

  1. CTRL-v
  2. jj..j all the lines you want
  3. do some command or motion, for example:
    • I - insert text in front of cursor
    • A - insert text after cursor
    • d - delete
    • r - replace character in selection
    • c - delete and switch to insert mode
    • $ or ^ - move to beginning or end of all selected lines
  4. esc enter normal mode