Vi editor
vi (visual) is a display-oriented text editor based on an underlying line editor ex. It is possible to use the command mode of ex from within vi and vice-versa. vi is available on most Unix systems. When using vi, changes you make to the file are reflected in what you see on your terminal screen. The position of the cursor on the screen indicates the position within the file.
To edit a file, type
[user@helix ~]$ vi filename
The man pages for vi are available (type man vi at the prompt) or on the web.
A summary of vi commands is below for your convenience. Ctrl-b means hold down the Control key and hit b.
Esc | Change from Insert mode to Command mode | ||||||||||||||||||
Ctrl-Z | Suspend vi process (fg to resume) | ||||||||||||||||||
:wq | Normal exit, saving file first (Alternate form: ZZ) | ||||||||||||||||||
:w | Save current file (write to disk) | ||||||||||||||||||
:q! | Quit (abnormal exit) ? restore state to last write | ||||||||||||||||||
Ctrl-F | View next screen | ||||||||||||||||||
Ctrl-B | View previous screen | ||||||||||||||||||
Ctrl-L | Repaint screen (Alt: Ctrl-R) | ||||||||||||||||||
l | Advance one char (Alt: arrow keys or Space/Backspace) | ||||||||||||||||||
h | back up one char (Alt: arrow keys or Space/Backspace) | ||||||||||||||||||
w | Advance one word (Capitalize to skip puncuation) | ||||||||||||||||||
b | back up one word (Capitalize to skip puncuation) | ||||||||||||||||||
j | Advance vertically (Alt: arrow keys or Ctrl-N/Ctrl-P) | ||||||||||||||||||
k | Back up vertically (Alt: arrow keys or Ctrl-N/Ctrl-P) | ||||||||||||||||||
:n | Go to line n | ||||||||||||||||||
H | Go to highest line of screen | ||||||||||||||||||
M | Go to middle line of screen | ||||||||||||||||||
L | Go to lowest line of screen | ||||||||||||||||||
0 | Go to start of current line | ||||||||||||||||||
$ | Go to end of current line | ||||||||||||||||||
( | Go to start of current sentence | ||||||||||||||||||
) | Go to start of next sentence | ||||||||||||||||||
1G | Go to top of file | ||||||||||||||||||
G | Go to bottom of file | ||||||||||||||||||
u | Undo last change | ||||||||||||||||||
U | Restore current line | ||||||||||||||||||
i | Insert left of cursor | ||||||||||||||||||
O | Open line (and enter Insert mode) above current line | ||||||||||||||||||
o | Open line (and enter Insert mode) below current line | ||||||||||||||||||
a | Append (insert) after cursor | ||||||||||||||||||
A | Append (insert) at end of current line | ||||||||||||||||||
J | Join the next line to the end of the current line | ||||||||||||||||||
Ctrl-D | Unindent relative to previous line (Insert mode, at line start) | ||||||||||||||||||
x | Delete current character | ||||||||||||||||||
X | Delete previous character | ||||||||||||||||||
dw | Delete rest of current word | ||||||||||||||||||
dd | Kill entire line | ||||||||||||||||||
P | Paste before cursor the contents of last delete | ||||||||||||||||||
p | Paste after cursor the contents of last delete | ||||||||||||||||||
"np | Paste below current line nth (1st thru 9th) delete from last | ||||||||||||||||||
"bdd | Delete line into buffer b (26 lettered buffers) | ||||||||||||||||||
"bp | Paste contents of buffer b | ||||||||||||||||||
:rfile | Read in (insert) file | ||||||||||||||||||
:efile | Edit another file | ||||||||||||||||||
/patternSearch forward for
pattern
| ?pattern | Search backward for pattern
| n
| Repeat previous search
in same direction
| N
| Repeat previous search
in opposite direction
| :g/old/s//new/g
| Multiple replacements
| :g/old/s//new/c
| Interactive replacements
| :s/old/new
| Substitute for first occurence in line | append /g, /c for global, interactive substitution cwtext
| Change remainder of
word to text (end with | :map x macro
| Define character x as macro ? cf. reference!
| @b
| Execute (as macro) contents of buffer b ? cf. reference!
| |
Note: Many commands may be preceded by a count or a range of line numbers