Archive for the ‘Linux/Unix’ Category

Vi Survival Commands

Thursday, May 21st, 2009
Command Action
vi Starts the Vi editor
vi <filename> Starts Vi and opens the given file for editing
:q! Exits the Vi editor without saving changes (quit!)
:wq! Exits the Vi editor and saves changes (write and quit!)
:set nu Turns on line numbering
esc Exits text insert mode
i Enters text insert mode
Arrow keys Navigates the cursor
Backspace key Deletes previous character
Delete Deletes selected character

Vi has two different running modes: command mode and edit mode. In command mode, every keystroke is interpreted as a command and performs file functions such as editing and saving. These commands are referred to as colon commands because they start with a colon. You know you’re in command mode because you won’t see “INSERT” in the lower-left corner of your display. The lower-left corner should display a colon when executing colon commands. If you have any doubts as to what mode you’re in, press the Escape key (several times) to enter command mode.

In text mode, typed characters are echoed to the screen and temporarily become part of the open document. Enter text mode from command mode by typing a lowercase i (for insert mode). Use the arrow keys to navigate the cursor, and use the Backspace and Delete keys to remove characters. To quit without saving your current work, or to save your current work and quit, refer to Table 5-3.