How do I use the vi text editor?
The vi text editor has three modes: command mode, input mode, and ex mode.
Command mode
When starting, vi begins in command mode. If you are ever unsure which mode
you're in, press Esc to return to command mode. In command
mode, you can move around with the arrow keys, or by using the vi
movement keys, as follows:
h |
left |
j |
down |
k |
up |
l |
right |
Several vi commands are listed in the table below:
| Command | Action |
|---|---|
Ctrl-b |
Go back one page |
Ctrl-f |
Go forward one page |
x |
Delete the character the cursor is on |
Shift-x |
Delete the character before the cursor |
dd |
Delete the current line |
Shift-d |
Delete everything from the cursor to the end of the line |
u |
Undelete a line you just deleted |
Shift-u |
Undo all changes to the current line |
Shift-z-z |
Save your file and exit the vi editor |
Note: In command mode, you can type a number before
pressing a command key to repeat the command multiple times. For
example, to delete eight lines from the cursor position, you could
press 8 and then type
dd .
Input mode
The input mode lets you insert or append text. To insert text before
the cursor's current position, in command mode, press
i . Similarly, to append after the cursor,
you can type a . Remember that you can't move
around with the cursor keys in this mode. When you're done entering
text, press Esc to go back to command mode.
Ex mode
The ex mode is an extension of command mode. To get into it, press
Esc and then : (the colon). The
cursor will go to the bottom of the screen at a colon prompt. Write
your file by entering :w and quit by entering
:q . You can combine these to save and exit by
entering :wq . However, if you're finished
with your file, it's generally more convenient to type
Shift-z-z from command mode.
For a more thorough list of vi command keys, see A quick reference list of vi editor commands.
At Indiana University, to get support for personal or departmental Linux or Unix systems, see At IU, how do I get support for Linux or Unix?
Also see:
- In Unix, what is Ispell and how do I use it to spell-check files?
- In Unix, how do I set my default (preferred) editor?
- In vi, how can I perform a global search and replace?
- In vi, how do I set up line-wrapping and do paragraph filling?
- In vi, how can I access deleted text?
- What is Pico?
- How do I make the vi editor display or hide line numbers?
- How do I quit the vi editor without saving my changes?
- A quick reference list of vi editor commands
- In vi, can I retrieve a document I was editing when I lost my connection?
- When using vi to edit a large file, what should I do if I get the "not enough space" error message?
Last modified on August 22, 2008.






