| Cursor | |
h | move left |
l | move right |
j | move down |
k | move up |
w, W/b, B | move forward/backward by word |
e | move to end of word |
E | move to end of word (includes punctuation) |
), ( | beginning of next, previous sentence |
}, { | beginning of next, previous paragraph |
]], [[ | beginning of next, previous section (normally defined by an opening '{') |
| | |
| Scrolling | |
[CTRL-F], [CTRL-B] | Scroll forward, backward one screen |
[CTRL-D], [CTRL-U] | Scroll down, up one-half screen |
[CTRL-E], [CTRL-Y] | Scroll down, up one line |
z [RETURN] | Scroll so that line with cursor is at top of screen |
z . | Scroll so that line with cursor is at middle of screen |
z - | Scroll so that line with cursor is at bottom of screen |
[CTRL-L] | Redraw screen (without scrolling) |
| | |
| Line number |
[CTRL-G] | Display current line number |
nG | Move to line number n |
G | Move to last line in file |
:n | Move to line n |
| | |
| Insert | |
i, a | Insert text before, after cursor |
I, A | Insert text before beginning, after end of line |
o, O | Open new line for text below, above cursor |
| | |
| Delete/Move | |
x | Delete character under cursor |
X | Delete character before cursor |
dw | Delete word |
dd | Delete current line |
dmotion | Delete text between cursor and the target of motion |
D | Delete to the end of line |
p, P | Put deleted text after, before cursor |
"np | Put text from delete buffer number n after cursor (for last nine deletions)
| | | |
| Exit commands | |
ZZ | Write (save) the file if modified, and quit file |
:x | Write (save) the file if modified, and quit file |
:wq | Write (save) the file unconditionally, and quit the file |
:w | Write (save) the file |
:w! | Write (save) the file, overriding protection |
:30, 60w newfile | Write from line 30 through line 60 to newfile |
:30, 60w>>file | Write from line 30 through line 60 and append to file |
:w %.new | Write current buffer named file as file.new |
:q | Quit file |
:q! | Quit file, overriding protection |
Q | Quit vi and invoke ex |
:e file2 | Edit file2 without leaving vi |
:r newfile | Read contents of newfile into current file |
:n | Edit next file |
:e! | Return to version of current file at time of last write (save) |
:e # | Edit alternate file |
:vi | Invoke vi from ex |
: | Invoke one ex command from vi editor |
% | Current filename (substitutes into ex command line) |
# | Alternate filename (substitutes into ex command line) |
^] | Look up the location of the identifier under the cursor in the tags file and move to that location. If tag stacking is enabled, the current location is automatically pushed onto the tag stack. |
^T | Return to the previous location in the tag stack, i.e. pop off one element |
|
|
| Lines |
|
[RETURN] | First non-blank character of next line |
0, $ | First, last position of current line |
^ | First non-blank character of current line |
+, - | First non-blank character of next, previous line |
n| | Column n of current line |
H | Top line of screen |
M | Middle line of screen |
L | Last line of screen |
nH | n (number) of lines after top line |
nL | n (number) of lines before last line |
| | |
| Searches |
/pattern | Search forward for pattern |
?pattern | Search backward for pattern |
n, N | Repeat last search in same, opposite direction |
/, ? | Repeat previous search forward, backward |
fx | Search forward for character x in current line |
Fx | Search backward for character x in current line |
tx | Search forward to character before x in current line |
Tx | Search backward to character after x in current line |
; | Repeat previous current-line search |
, | Repeat previous current-line search in opposite direction |
:1,$s/x/y/g | Globally replace x with y |
| | |
| Marking position | |
mx | Mark current position as x |
`x | Move cursor to mark x |
`` | Return to previous mark or context |
'x | Move to beginning of line containing mark x |
'' | Return to beginning of line containing previous mark |
| | |
| Change | |
r | Replace character |
cw | Change word |
cc | Change current line |
cmotion | Change text between the cursor and the target of motion |
C | Change to end of line |
R | Type over (overwrite) characters |
s | Substitute: delete character and insert new text |
S | Substitute: delete current line and insert new text |
| | |
| Yank (copy) | |
yw | Yank (copy) word |
yy | Yank current line |
"ayy | Yank current line into named buffer a (a-z). Uppercase names append text. |
ymotion | Yank text between the cursor and the target of motion |
p, P | Put yanked text after, before cursor |
"aP | Put text from buffer a before cursor (a-z) |
| | |
| ex edit commands | |
:d | Delete lines |
:m | Move lines |
:co or :t | Copy lines |
:.,$d | Delete from current line to end of file |
:30, 60m0 | Move lines 30 through 60 to top of file |
:.,/pattern/co$ | Copy from current line through line containing pattern to end of file |
| | |
| Other commands | |
. | Repeat last edit command |
u, U | Undo last edit; restore current line |
J | Join two lines |
|