vi has 2 modes, command mode and insert mode. In command mode, everything
you type is a command, in insert mode what you type is written to the screen
(file buffer). vi starts in command mode. The more complex commands start with
: and appear at the bottom of the screen, you need to press ENTER to execute
them.
To enter insert mode you can press:
- i - to start inserting at the current cursor position
- I - to start inserting at the beggining of the line
- a - to start append after the current cursor position
- A - to start appending at the end of line
- o - append a new line and start editing
- O - insert a new line and start editing
To exit command mode you press ESCAPE
To move around in command mode you can use the arrow keys in modern vi
implementation. Otherwise the keys to move around are:
- h - left
- j - down
- k - up
- l - right
Other useful movement commands
- 0 - start of line
- $ - end of line
- :nn - goto line nn
- G - end of file
Some editing commands. They can be prepended by a number of times to repeat
the command, i.e. 4dd will cut 4 lines.
- dd - cut line (delete)
- yy - copy line (yank)
- p - paste after cursor
- P - paste before cursor
File commands (remember to follow by ENTER)
- :w - save file
- :w filename - save as 'filename'
- :q - quit
- :q! - quit without saving
- :e file - open a file
- :r file - insert (read) a file
Other miscelaneous commands
- /patter - search for pattern forward
- ?patter - search for pattern backwards
- :s/orig/new/ - search and replace in current line
- :%s/orig/new/ - search and replace throughout the whole file
- !command - execute a shell command
I personally recommend the use of vim,
which gives you many useful features over simple vi such as:
- full use of arrow keys
- syntax highlighting
- indentation
- screen spliting
- multiple buffers management
- tags
Ignacio Solis -
[ @igso ]
[ @ucsc ]
[ @sluglug ]
[ knowledgebase ]
[ blog ]
Mail any questions or comments to isolis @ igso.net
Last updated Mar 31, 2004