Vi er indbygget på de fleste Unix maskiner. Til en Windows maskine kan du hente
vi.exe eller se på
VIMs hjemmeside.
| Cursor Movement Commands |
| h |
Moves the cursor one character to the left |
| l |
Moves the cursor one character to the right |
| k |
Moves the cursor up one line |
| j |
Moves the cursor down one line |
| nG or :n |
Cursor goes to the specified (n) line, ex. 10G goes to line 10 |
| ^F |
Forward screenful |
| ^B |
Backward screenful |
| ^f |
One page forward |
| ^b |
One page backward |
| ^U |
Up half screenful |
| ^D |
Down half screenful |
| $ |
Move cursor to the end of current line |
| 0 |
Move cursor to the beginning of current line |
| w |
Forward one word |
| b |
Backward one word |
| Text Entry Commands (Used to start text entry) |
| a |
Append text following current cursor position |
| A |
Append text to the end of current line |
| i |
Insert text before the current cursor position |
| I |
Insert text at the beginning of the cursor line |
| o |
Open up a new line following the current line and add text there |
| O |
Open up a new line in front of the current line and add text there |
| NOTE: While you are in text entry mode, you will have to
press <ESC> in order to return to the command mode so you can move the cursor or use any of the other text editing commands. |
| Text Deletion Commands |
| x |
Delete character |
| dw |
Delete word from cursor on |
| db |
Delete word backward |
| dd |
Delete line |
| d$ |
Delete to end of line |
| d^ |
Delete to beginning of line |
| Yank |
(has most of the options of delete)-- VI's copy commmand |
| yy |
yank current line |
| y$ |
yank to end of current line from cursor |
| yw |
yank from cursor to end of current word |
| 5yy yank |
for example, 5 lines |
| Paste |
(used after delete or yank to recover lines.) |
| p |
paste below cursor |
| P |
paste above cursor |
| "2p |
paste from buffer 2 (there are 9) |
| u |
Undo last change |
| U |
Restore line |
| J |
Join next line down to the end of the current line |
| File Manipulation Commands |
| :w |
Write workspace to original file |
| :w |
file Write workspace to named file |
| :e |
file Start editing a new file |
| :r |
file Read contents of a file to the workspace |
| To create a page break, while in the insert mode, press the CTRL key And l. ^L will appear
in your text and will cause the printer to start A new page. |
| Exit Commands |
| :wq |
Write file to disk and quit the editor |
| :q! |
Quit (no warning) |
| :q |
Quit (a warning is printed if a modified file has not been saved) |
| ZZ |
Save workspace and quit the editor (same as :wq) |
| : 10,25 w temp |
write lines 10 through 25 into file named temp. Of course, other line numbers can be used. (Use :f to find out the line numbers you want. |
| Other Useful Commands |
| Most commands can be repeated n times by typing a number, n, before the command. For example 10dd means delete 10 lines. |
| . |
Repeat last command |
| cw |
Change current word to a new word |
| r |
Replace one character at the cursor position |
| R |
Begin overstrike or replace mode - use ESC key to exit |
| :/ pattern |
Search forward for the pattern |
| :? pattern |
Search backward for the pattern |
| n |
(used after either of the 2 search commands above to continue to find next occurrence of the pattern, N repeats search backwards. |
| :g/pat1/s//pat2/g |
replace every occurrence of pattern1 (pat1) with pat2 (Example :g/txIO/s//Ada.Text_IO/g This will find and replace txIO by
Ada.text_IO everywhere in the file. |
| :g/a/s// /g |
replace the letter a, by blank |
| :g/a/s///g |
replace a by nothing |
| [ESC][ESC]:g/pattern1/s//pattern2/g |
Replaces every occurrence of pattern1 with pattern2 |