docs:vim:commands

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
gi insert text in the same position as where insert mode was last stopped
a
A
append at cursor/append at end of current line
o
O
begin a new line below/above the 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

A motion is a command that moves the cursor. You can use motions with many other commands when not in insert mode.

w
e
to start/end of word
b to beginning of word
4j 4 lines down
f{char}
F{char}
forward on current line to the next occurrence of {char} inclusive/exclusive
t{char}
T{char}
backward on current line to the previous occurrence of {char} inclusive/exclusive
; Repeat latest f, t, F or T [count] times
, Repeat latest f, t, F or T in opposite direction [count] times
[number]gg
[number]G
go to line number, or first line if [number] is excluded
(
)
move sentences forward/backward
{
}
move paragraphs forward/backward

These commands word in Visual modes.

aw a word, trailing whitespace is included
iw inner word
a[
a]
a [] block (use i for inner block)
a(
a)
ab
a () block (use i for inner block)
a<
a>
a <> block (use i for inner block)
a{
a}
a {} block (use i for inner block)

FIXME

ga show value of character under the cursor in decimal, hex, and octal
g8 show the hex values of the bytes used in the character under the cursor

:help ins-completion

:help abbreviations

You can use abbreviations to quickly enter a short sequence of characters that will be expanded into your defined sequence of characters. This can be useful to avoid typing monotonous things such as “document.getElementById” or to correct common spelling mistakes such as “teh” etc…

Examples:

:ab de document.getElementById(' now type de<space>, and de turns
into document.getElementById('
: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.txt
  • Last modified: 2008/08/03 00:25
  • by 127.0.0.1