vi Editor Minimal Reference
Here's how to start editing a file called filename.txt. If that
file doesn't exist, it will be created:
$ vi filename.txt
vi commands
(enter these once you start the vi editor)
|
Many of these commands happen immediately, without requiring
you to press the Enter key. The ones that start with
the characters : / or ? require that
you press return
after entering the command. Just watch what happens; if nothing
happens, press the Enter (or Return) key.
|
| Command | Purpose |
| Control |
| Esc |
(Esc key) puts you into command mode so that you
can enter commands
|
| i |
puts you into insert mode so that the characters you
type will start to appear
at the current cursor position
|
| o |
puts you into insert mode so that the characters you
type will start to appear on
the line after
at the current cursor position
|
| File Management |
| :w |
save the current editor's contents to the file
that you opened vi with
|
| :w filename | write the current editor's contents to a file called filename; |
| :w! filename | write the current editor's contents to a file called filename, overwriting it if it already exists; |
| :q | quit vi without saving any changes |
| ZZ | save the current contents of the editor to the filename that you opened it with and then exit vi |
| Informational |
| Ctrl/g | (press Ctrl and g at the same time) displays your current line number |
| /string | searches for string in file in a forward direction; moves your cursor right to it if found; repeat string search with just / |
| ?string | searches for string in file in a backward direction; moves your cursor right to it if found; repeat string search with just ? |
| Moving the Cursor |
| space bar | (space bar) moves cursor to the right |
| backspace | (backspace key) moves cursor to the left |
| j | moves cursor down |
| k | moves cursor up |
| Text cutting, copying, and pasting |
| x | deletes text under cursor |
| dw | deletes the rest of the current word under cursor |
| dd | deletes line under cursor |
| Y | copy (yank) the current line under cursor into the buffer |
| p | pastes buffer (last delete or yank) |
| Text changes |
| :1,$ s/old/new/g |
change all occurences in the file of old
to new
|
| J |
joins line below the cursor with the current line
|
More vi Resources
- Use "VI Tutorial," from Engineering Computer Network, Purdue University,
West Lafayette, Indiana, USA
is a very thorough Web-based instructional guide on vi.