Help:Vi keys grouped by function
<<Back to Help:vi
Vi is a modal editor. Different keys have different results in different modes.
Unassigned keys[edit]
The following keys have no assignment by default in vi. In insert mode, your termal's stty setting might assign a function to some of these control characters. All of these unassigned keys should be available for alias (macro) assignment.
Unassigned keys: ^A^I ^K ^O ^Q ^R ^S ^W ^X # * = K V g q v
Screen positioning[edit]
^D | Scroll the window down one half screen. |
^E | Scroll the screen up one line. |
^F | Scroll forward one screen. |
^L | Clear and redraw the screen without changing position. |
^U | Scroll the window up one half screen. |
^Y | Scroll the screen down one line. |
z return | Redraw the screen with the current line at the top |
z. | Redraw the screen with the current line at the middle |
z- | Redraw the screen with the current line at the bottom |
Movement keys[edit]
Move by (possibly) more than a line[edit]
^B | Move backward one screen. |
^] | Moves to the tag whose name is given by the word in which the cursor resides (may change files) |
% | Move to the parenthesis, brace or bracket ( ) { } [ ] matching the one at or after the current position. |
( | Move back to the start of a sentence. |
) | Move forward to the start of the next sentence. |
{ | Move backwards one blank line delimited paragraph |
} | Move forwards one blank line delimited paragraph |
[[ | Move backward one C function. |
]] | Move forward one C function. |
` (backtick) | Move to the character position of the given mark (or last context if doubled) |
' (tick) | Move to the line containing the given mark (or last context if doubled) |
/ | Start of a forward string search command. String searches may be optionally terminated with a closing slash. To search for a slash use '\/' in the search string. |
? | (move) String search backwards (reverse of / ) |
G | Move (Go) to the given line number (end of file, by default). |
H | Move to the first non-white char. on the top screen line. |
L | Move to the first non-white char. on the bottom screen line. |
M | Move to the first non-white char. on the middle screen line. |
N | Reverse the last string search. |
n | (move) Repeat the last string search. |
Move by a line[edit]
^J | Move the cursor down one line. |
^M (CR) | Move to the first non-white character in the next line. In insert mode, a carriage return opens a new line for input. |
^N | Move the cursor down a line. |
^P | Move the cursor up a line. |
- | Move to the first non-white character in the previous line. |
+ | Move to the first non-white character in the next line. |
_ (underscore) | Move to the start of the line, or the nth line if given a count |
j | Move down one line. |
k | Move up one line. |
Move within a line[edit]
^H (BS) | Moves cursor left one space in command mode. In insert mode, erases the last character typed. |
SPACE | Move the cursor right on column. |
$ | Move to the end of the current line. |
^ | Move to the first non-white on the current line. |
| | Move to the column given by the preceding count. |
, (comma) | Move reverse of the last t, T, f, or F command. |
0 | Move to the start of the current line. Also used within counts. |
; | Move: repeat last t, T, f, or F command. |
B | Move backward one blank-delimited word. |
E | Move to the end of a blank-delimited word. |
F | (Move) Find a character backward on the current line. |
T | (Move) Reverse search 'upto' the given character. |
W | Move forward one blank-delimited word. |
b | Move back one word. |
e | Move to the end of a word. |
f | (move) Find a character on the current line. |
h | Move left one column. |
l | Move right one column. |
t | Move forward 'upto' the given character on the current line. |
w | Move forward one word. |
Operators[edit]
When doubled, operators work on a line (or multiple lines if preceeded by a count). When combined with a movement key, they operate on the section of text moved over. For example:
dw deletes a word dd deletes a line 2dd deletes two lines
The operators are as follows:
C | Change the rest of the current line (enters insert mode) |
c | change operator (enters insert mode) |
d | delete operator |
< | left shift operator |
> | right shift operator |
! | Operate on text by running a command over it; text becomes input to the command; output from the command replaces the text. |
Enter insert mode[edit]
These keys cause vi to enter insert mode. Note that several of these are also operators or take repeat counts to delete text before inserting.
A | Append at the end of the current line. |
C | (insert) Change the rest of the current line. |
I | Insert before the first non-white char. on the current line. |
J | Join two lines. |
O | Open a new line above the current line, and start inserting. |
R | Replace characters until esc is typed (not exactly insert mode) |
S | Change entire current line (insert) |
a | Append text after the cursor. |
c | change operator (insert) |
i | Insert text before the cursor. |
m | Set a mark at the current position (e.g. ma or mb). |
o | Open a new line and start inserting text. |
s | Replace characters (use count to replace several, enters insert mode) |
line editing keys[edit]
These keys probably follow those set by stty, and can be used in insert mode, when typing in a search string for / or ?, and when typing an ex command line.
^H | backspace |
^D | unindent one shift width |
0 ^D | cancel autoindent offset, move to left margin |
^U | kill current input line |
^V | In insert mode, next character is taken literally |
ESC | exit insert mode and return to command mode |
CR | open a new line for input, at the current autoindent offset (if on) |
Other[edit]
^C | interrupt pending operation (search, file I/O, others) |
^G | Same as ":f" command. Displays file information. |
^T | Tag stack |
^Z | Stop vi (see shell job control) |
D | Delete the rest of the current line. |
P | Put the yank/delete buffer before the current cursor position. |
Q | quit vi and go to ex mode (type vi to come back) |
R | Replace characters until esc is typed |
U | Undo all (recent) changes on current line |
X | Delete the character before the cursor. |
Y | Yank the current line. Same as 'yy'. |
ZZ | Exit from the editor, saving changes if necessary. |
p | Put the yank/delete buffer after the cursor. |
r | Replace a character (count replaces several with one character repeated) |
s | Replace characters (use count to replace several, enters insert mode) |
u | Undo the last edit. |
x | Delete the character under the cursor. |
y | yank operator |
~ | toggle case of letter under cursor and move to next character |
. | Repeat the last edit command. |
: | Prefix character for "ex" commands. |
& | repeat the last search and replace on the current line (:s) |
"x | next yank or delete goes in register x |
@x | run vi commands in register x as if typed |