This is an old revision of the document!


VIM Commands

  • you can start the VIM tutor by typing 'vimtutor' at a command prompt
  • :!: make sure to read the reference_documents
h, j, k, l move left, down, up, right
$ or END jump to the end of the current line
<html>&#094;</html> or HOME jump to the beginning of the current line
Shift-G go to end of file
<number> Shift-G go to line <number> of file; i.e.: '1 Shift-g' to go to first line
Ctrl-e scroll window downwards by line
Ctrl-y scroll window upwards by line
Ctrl-f scroll window page forward (down)
Ctrl-b scroll window page back (up)
Ctrl-] jump (follow) the keyword tag under the cursor
Ctrl-t move back to the previous tag location
Ctrl-g show line/percentage location in file and file status
:q quit
:q! quit without saving changes
ZZ immediately exit saving changes
ZQ immediately exit without saving changes
:w save changes
:wq save changes and quit
:! <command> execute an external command, such as dir, ls, etc…
:r <filename> insert the contents of a file
/ <searchterm> begin search for <searchterm>
n continue searching the file for <searchterm>
Shift-N search in the opposite direction
? <searchterm> begin backwards search for <searchterm>
% find matching ), ], or }
:s/old/new search and replace the first occurance of 'old' with 'new' in the current line
:s/old/new/g search and replace all occurances of 'old' with 'new' in the current line
:#,#s/old/new/g search and replace all occurances of 'old' with 'new' between the two line numbers (#,#)
:%s/old/new/g search and replace all occurances of 'old' with 'new' in the whole file
:%s/old/new/gc search and replace all occurances of 'old' with 'new' in the whole file,
asking for confirmation each time
Ctrl-w w switch to next window
Ctrl-w Shift-W switch to previous window
Ctrl-w <number> -reduce the height of the current window by <number> lines
Ctrl-w <number> +increase the height of the current window by <number> lines
Ctrl-w s
:split
create another window for the current buffer (horizontal)
Ctrl-w v
:vsplit
create another window for the current buffer (vertical)
Ctrl-w c
:close
close current window
Ctrl-w n
:new
create a new window and start editing an empty file in it
Ctrl-w q
:q
:quit
quit current window; when quitting the last window, exit VIM
p/P put (paste below/above)
v/V block select (characterwise/linewise) mode
[number]yy yank <number> of lines into register (copy)
y (after block select) yank (copy)
d (after block select) delete (cut)
gv restore previous selection
(useful after indent if you need to indent again)
:reg show current registers (like current clipboard entries)
“[char][command] char: register to use, command: p/P/y
(if yanking, you probably want to block select first)
i/I insert at cursor/insert at beginning of current line
a/A append at cursor/append at end of current line
r/R replace one char under cursor/replace until escape is pressed
c<motion> change with motion
C change from cursor to end of line
cw change word (delete remaining portion of the word, and begin editing)
c(same options as d) change line, change word etc…
d<motion> delete with motion
dd delete line
de delete word (no space)
dw delete word
d$ delete to end of line
d<html>&#094</html> delete to beginning of line
u undo
U undo all for line
Ctrl-r undo an undo (reverse direction)
>/» indent in block select mode, indent current line
</« outdent in block select mode, outdent current line

:help ins-completion

:se[t] show all options that differ from their default value
:se[t] all show all but terminal options
:se[t] {option}? show value of option
:se[t] {option} Toggle option: set, switch it on.
Number option: show value.
String option: show value.
:se[t] no{option} Toggle option: Invert value.
:se[t] {option}& Reset option to its default value.
:opt[ions]
:bro[wse] se[t]
open a window for viewing and setting all options
:mk[exrc] [file]
:mk[exrc]! [file]
write, always write current key mappings and changed options to [file]
:mkv[imrc][!] [file] (like :mk, but the default is .vimrc)

(see above for usage)

'number' 'nu'line numbers for each line
'spell' spell check
'wrap' line wrapping
'list' list mode (tabs as ctrl-i, end of line as $)
'linebreak' 'lbr' wrap at word
'expandtab' 'et' expand-tab (tabs expanded into spaces)
'autoindent' 'ai' auto-indent (copy indent from current line)
'cindent' 'cin' C program indenting
'smartindent' 'si' smart indenting (like cin, but supposed to work better and is less strict)
'smarttab' 'sta' FIXME
  • docs/vim/commands.1199074172.txt.gz
  • Last modified: 2008/08/03 00:25
  • (external edit)