Basic Vi (Vim) Commands

Curson movement

:12
move to line 12
^
first non-blank character of line
$
end of line
w
jump by start of words (punctuation considered words)
W
jump by words (spaces separate words)
e
jump to end of words (punctuation considered words)
E
jump to end of words (no punctuation)
b
jump backward by words (punctuation considered words)
B
jump backward by words (no punctuation)
0
(zero) start of line

Copy and Paste

yy (yank)
copy line
2yy
copy 2 lines
dd
delete (cut) line
2dd
delete (cut) next current and next lines
p
paste after the cursor
P
paste before the cursor
dw
delete (cut) the current word
x
delete (cut) the current character
j
join lines

Undo and Repeat

u
undu
.
repaet last opertation
x
delete backwards
A
inserte at the end of the line

search

Example of search and substitution
:1,$/something/SOMETHINGelsegi
:
search
1,$
from line 1 to the end
/something
search for the word "something"
/SOMETHINGelse
repalece with the word "SOMETNINGeslse"
g
global option
i
case insensitive option

Search forwards

  • Enter the normal mode
  • Press /
  • Type your search pattern
Esc
to cancel
Enter
to perform the search.

Search backwards

  • Enter the normal mode
  • Press ?
  • Type your search pattern
n
Next occurrence. Search forwards for the next occurrence
N
search backwards.
ggn
jump to the first match
GN
jump to the last.
??
reverse occurrence
cw
change word

Search for the current word

  • Enter the normal mode
  • Move the cursor to any word
*
search forwards for the next occurrence of that word
#
to search backwards
* or # searches
Search for the exact word at the cursor (searching for rain would not find rainbow).
g* or g#
if you don't want to search for the exact word.

SearchingEdit

This needs a GUI version of Vim (gvim), or a console Vim that accepts a mouse.

You may need to comfigure the vimrc file to enable mouse searches...