|

Some useful vi commands
To start, enter vi [filename] at the prompt
There are 2 modes in vi. Input/Insert mode,
where you enter text, and Command mode, where you enter vi
commands.
| a |
Append text to right of the cursor
|
| A |
Append text to end of line |
| i |
Insert text at current cursor position |
| I |
Insert text at end of line |
| o |
Insert new line below current line |
| O |
Insert new line above current line |
| :q |
Quit vi |
| :q! |
Quit vi, do not save changes |
| R |
Type over mode, with insert mode at end of line |
| cw |
Change current word with text you type |
| cc |
Change entire line with text you type |
| dd |
Delete the current line |
| D |
Delete line from cursor to end of line |
| d^ |
Delete line from beginning to cursor |
| dG |
Delete from cursor to end of file |
| u |
Undo the last change made |
| x |
Delete character cursor is on |
| X |
Delete character to left of cursor |
| :w [file] |
Write file, optionally to
file |
| ZZ or :wq |
Write the file, then quit |
| :r file |
Insert file at cursor position |
| p |
Paste last text copied to right of cursor |
| P |
Paste text to left of cursor |
| yy or Y |
Yank (copy) current line |
| / |
Repeat the last forward search |
| n |
Next, repeat last search (forward or backward) |
| N |
Next, repeat last search in opposite direction |
| /find text |
Search from cursor forward for find text |
| :s/findtext/replacetext |
Replace find text with replace text on
current line |
| :%s/findtext/replacetext/g |
Replace all occurances of find text |
| j or <enter> |
Move down 1 line |
| k |
Move up 1 line |
| l or <space> |
Move left 1 character |
| h or <backspace> |
Move right 1 character |
| 0 |
Move to the beginning of the line |
| $ |
Move to the end of the line |
| G |
Move to the end of the file |
| w |
Move forward 1 word |
| b |
Move back 1 word |
| <ctrl>f |
Move down 1 screen |
| <ctrl>b |
Move up 1 screen |
Back to Top
Please send your comments and suggestions about this
web page to C. Brower
(brower@bst.rochester.edu)
|