Some versions of vi do not recognize extended keyboard keys (e.g., arrow keys, Page Up, Page Down, Home, Insert, and Delete); some do. All, however, recognize the keys in this section. Many users of vi prefer to use these keys, as it helps them keep their fingers on the home row of the keyboard. A number preceding a command repeats the movement. Movement commands are also objects for change, delete, and yank operations.
Action |
|
---|---|
h, j, k, l |
Left, down, up, right (←, ↓, ↑, →) |
Spacebar |
Right |
Backspace |
Left |
Ctrl-H |
Left |
Action |
|
---|---|
w, b |
Forward, backward by word (treating punctuation marks as words). |
W, B |
Forward, backward by word (recognizing only whitespace, not punctuation, as separators). |
e |
End of word (treating a punctuation mark as the end of a word). |
E |
End of word (recognizing only whitespace as the end of a word). |
ge |
End of previous word (treating a punctuation mark as the end of a word). {vim} |
gE |
End of previous word (recognizing only whitespace as the end of a word). {vim} |
), ( |
Beginning of next, current sentence. |
}, { |
Beginning of next, current paragraph. |
]], [[ |
Beginning of next, current section. |
][, [ ] |
End of next, current section. {vim} |
Long lines in a file may show up on the screen as multiple lines. While most commands work on the lines as defined in the file, a few commands work on lines as they appear on the screen.
Command |
Action |
---|---|
0, $ |
First, last position of current line. |
^, _ |
First nonblank character of current line. |
+, - |
First character of next, previous line. |
Return |
First nonblank character of next line. |
n| |
Column n of current line. |
g0, g$ |
First, last position of screen line. {vim} |
g^ |
First nonblank character of screen line. {vim} |
gm |
Middle of screen line. {vim} |
gk, gj |
Move up, down one screen line. {vim} |
H |
Top line of screen. |
M |
Middle line of screen. |
L |
Last line of screen. |
nH |
n lines after top line of screen. |
nL |
n lines before last line of screen. |
Action |
|
---|---|
Ctrl-F, Ctrl-B |
Scroll forward, backward one screen. |
Ctrl-D, Ctrl-U |
Scroll down, up one-half screen. |
Ctrl-E, Ctrl-Y |
Show one more line at bottom, top of window. |
z Return |
Reposition line with cursor to top of screen. |
z. |
Reposition line with cursor to middle of screen. |
z- |
Reposition line with cursor to bottom of screen. |
Ctrl-L |
Redraw screen (without scrolling). |
Action |
|
---|---|
/pattern |
Search forward for pattern. |
/ |
Repeat previous search forward. |
/pattern/+n |
Go to line n after pattern. |
?pattern |
Search backward for pattern. |
? |
Repeat previous search backward. |
?pattern?-n |
Go to line n before pattern. |
n |
Repeat previous search. |
N |
Repeat previous search in opposite direction. |
% |
Find match of current parenthesis, brace, or bracket. |
* |
Search forward for word under cursor. Matches only exact words. {vim} |
# |
Search backward for word under cursor. Matches only exact words. {vim} |
g* |
Search backward for word under cursor. Matches the characters of this word when embedded in a longer word. {vim} |
g# |
Search backward for word under cursor. Matches the characters of this word when embedded in a longer word. {vim} |
fx |
Move forward to x on current line. |
Fx |
Move backward to x on current line. |
tx |
Move forward to just before x in current line. |
Tx |
Move backward to just after x in current line. |
, |
Reverse search direction of last f, F, t, or T. |
; |
Repeat last character search (f, F, t, or T). |
:noh |
Suspend search highlighting until next search. {vim}. |
Action |
|
---|---|
Ctrl-G |
Display current filename and line number. |
gg |
Move to first line in file. {vim} |
nG |
Move to line number n. |
G |
Move to last line in file. |
:n |
Move to line number n. |
Action |
|
---|---|
mx |
Mark current position with character x. |
`x |
(backquote) Move cursor to mark x. |
'x |
(apostrophe) Move to start of line containing x. |
`` |
(backquotes) Return to previous mark (or location prior to search). |
'' |
(apostrophes) Like preceding, but return to start of line. |
'" |
(apostrophe quote) Move to position when last editing the file. {vim} |
`[,`] |
(backquote bracket) Move to beginning/end of previous text operation. {vim} |
'[,'] |
(apostrophe bracket) Like preceding, but return to start of line where operation occurred. {vim} |
`. |
(backquote period) Move to last change in file. {vim} |
'. |
(apostrophe period) Like preceding, but return to start of line. {vim} |
:marks |
Copyright © 2003 O'Reilly & Associates. All rights reserved.