Editing with vi
A built-in text editor of the Unix system is called vi. The name vi is derived from the shortest unambiguous abbreviation for the command visual.
- From the Unix system prompt, you start up vi by typing:
- This will open a file called filename. If a file of that name doesn't already exist, it starts a new one.
- Vi has a command mode and an insert (or "editing") mode. You're, initially, always in command mode. Commands:
- Use the a and i commands (see below) to get to editing mode.
- The escape key takes you out of editing mode and puts you back in command mode.
- Unless otherwise noted, enter the following commands by simply typing them; you don't need to press the Return key. Commands should be typed in lowercase letters, unless otherwise indicated. The current line refers to the line on which your cursor is placed.
For "append". Puts you in insert (or "editing") mode. Any characters that you type subsequently will be added to your file to the right of your cursor.
|i||For "insert". Puts you in editing mode (if you are in command mode); characters that you type subsequently will be inserted to the left of your cursor.|
|<Return>||Hitting the Return key starts a new line (if you are in editing mode).|
|<Esc>||Hitting the Esc key takes you out of insert (or "editing") mode and returns you to command mode.|
Common Keyboard Shortcuts
|h (or ←)||Moves your cursor one character to the left.|
|j (or ↓)||Moves your cursor down one line.|
|k (or ↑)||Moves your cursor up one line.|
|l (or →)||Moves your cursor one character to the right.|
|^f||Scroll forward one screenful.|
|^b||Scroll backward one screenful.|
|x||Deletes the character on which your cursor lies.|
||Deletes the current line.|
|u||Undoes your last command.|
|J||Joins the next line with the current line.|
|ZZ||Save your work and quit vi.|
|:w <Return>||Writes (saves) your changes. (Typed sequentially.)|
|:wq <Return>||Saves your changes and quits vi. (Typed sequentially.)|
|:q! <Return>||Quits vi without saving your changes. (Typed sequentially.)|