November 12, 2014 · linux vim

Little reminder for vim commands

Forgot needed key?

h - move left
j - move down
k - move up
1 - move right
w - move to next word
W - move to next blank delimited word
b - move to beginning of the word
B - move to beginning of blank delimited word
e - move to end of word
E - move to end of blank delimited word
( - move a sentence back
) - move a sentence forward
{ - move paragraph back
} - move paragraph forward
0 - move to beginning of line
^ - move to beginning of line
$ - move to end of line
nG - move to nth line of file
:n - move to nth line of file
G - move to last line of file
fc - move forward to 'c'
Fc - move backward to 'c'
H - move to top of screen
M - move to middle of screen
L - move to bottom of screen
% - move to associated(),{},[]

deleting text

x - delete character to the right
X - delete character to the left
D - delete to the end of line
dd - delete current line
:d - delete current line

searching

/string - search forward for string
?string - search back for string
n - search for next instance of string
N - for for previous instance of string

replace

:s/pattern/string/flags - replace pattern with string, according to flags
g - flag, replace all occurences
c - flag, confirm replaces
& - repeat last :s command

file operations

:w file - write to file
:r file - read file in after line
:n - go to next file
:p - go to previous file
:e file - edit file
!!cmd - replace line with output of cmd

tabs

gt - next tab
gT - previous tab
:tabnew - create tab
:tabclose - close tab (or :q as alternative)

other

:q - exit
:qall -exit ALL tabs
:u - undo last change
:U - undo all changes to line
:retab - convert tabs in spaces
:set expandtab - insert spaces instead tabulation (Tab key)
:set tabstop={number} - how much spaces insert
! - add to command to force it (e.g. force exit all tabs :qall!)

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus