The traditional editor for unix is vi (for visual ).
Vi is a dual-mode editor; one switches from command mode to edit mode, so the effect of any key depends on the context. To edit a file xxx (or to create it in the first place), the command is vi xxx .
Vi starts in the command mode; you will likely want to position the cursor (h, j, k, l) and enter insert mode (i). You can then type. To leave insert mode, press Esc ; to write the file and quit the editor type :wq and press Enter.
Here is a summary of the commands. Note that it is necessary to press Escape to leave any of the open-ended editing modes (for example, i is open-ended, but r is not). The Escape key is a general-purpose reset. The only consequence of pressing escape too many times is a beep.
Commands | :q | quit |
---|---|---|
:wq | write, then quit | |
:q! | quit, discard changes | |
:w name | write under a new name | |
Esc | reset (leave input mode) | |
There are two definitions of ___word___
| ||
Cursor positioning | h, j, k, l | left, down, up, right |
0, ^, $ | start, first nonblank position, end of line | |
Enter, - | move one line | |
^D, ^U | move half page | |
^F, ^B | move full page | |
###G | go to line ### | |
G | go to bottom | |
^L | redraw | |
Esc | reset | |
w, W | forward word (1) or word (2). | |
b, B | backward word | |
e, E | end of word | |
H, M, L | home, mid screen, lower screen | |
Editing | i, a | insert before (append after) cursor |
I, A | insert at start of (append to) line | |
x, X | delete at (before) cursor | |
o, O | open line after (before) current line | |
dd | delete a line | |
cc | change a line | |
cw | change a word | |
r | change (replace) one character | |
R | overwrite (until reset) | |
s | substitute for this character | |
S | substitute for this line | |
J | join next line to this | |
u | undo last change to the line | |
U | undo all changes to the line | |
yy | yank (paste in) line | |
p | put line | |
Sentences | >, < | forward, backward |
Find | fx, Fx | find character 'x' forward, backward |
semicolon, period | find next | |
tx, Tx | like f,F but stop one character short. | |
/xxx | forward search for xxx. | |
?xxx | backward search for xxx. |
A.E. Dec 2013