1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | page 11
Command Saving files and quitting vi
:e file edit file (save current file with :w first). You need to be in command mode to enter these commands. If you are still in editing (insert or replace mode), press Esc to get to the command mode. Type : (colon) to see if this character appears on the status bar. If it is, you are ready to type in a new editor command. If not, type Esc and retype : again.
:w save (write out) the file being edited.
:w file save as file.
:w! file save as an existing file.
:q quit vi.
:wq save the file and quit vi.
:x exit (save the file if it has changed) and quit vi.
:q! quit vi without saving changes.
Command Deleting Text
x In command mode, deletes a character under the cursor. Note that these commands do not require a preceding :.
10x deletes 10 characters from the cursor.
dw deletes word.
3dw deletes three words.
d0 deletes from the cursor to the beginning of line.
d$ deletes from the cursor to the end of line.
dd deletes the current line.
5dd deletes five lines.
d{ deletes to the beginning of paragraph.
d} deletes to the end of paragraph.
:1,. d deletes to the beginning of file.
:.,$ d deletes to the end of file.
:1,$ d deletes all text lines.




Command Text search and replace
/end searches the next occurrence of the word pattern end from the cursor position. For example, end, blend, ended. Use :set hlsearch described in the section to highlight all occurrences in the file.
?end searches the previous occurrence of the word end from the cursor position.
n repeats the most recent search, in the same direction.
N repeats the most recent search, in the opposite direction.
:s/w1/w2 replaces the first occurrence of the word w1 with w2.
:s/w1/w2/g replaces all occurrences of the word w1 with w2.
:s/w1/w2/gi replaces all occurrences of the word w1 with w2, ignoring case.
Command Miscellaneous
:set number displays the line number from 1. To turn off line number, use :set nonumber.
:set tabstop=n n sets the number of equivalent blank spaces to expand for each tab stop if pressing the tab key. For example, :set tabstop=4 sets the tab stop to 4 spaces. The default value is 8.
:set hlsearch highlights all results of a pattern search. To turn off highlights, use :set nohlsearch.
:set wrap sets word-wrap mode. If a text line is longer than the current window width, the text is wrapped to the next line. Use :set nowrap to turn off word-wrap mode so only one text line is shown per screen line.
:syntax off turns off color highlighting for syntax checking. Use :syntax on to enable syntax color highlighting useful to view program or script files.
:set all to see all available command options starting with : (colon).
:n goes to the line number n and places the cursor at the first column of line. If the line number does not exist, position the cursor at the last text line.
:split splits the screen horizontally. Type Ctrl W k to switch to the top window or Ctrl W j to switch to the bottom. To close either one of the split windows to leave the split screen mode, use q! to close.
Shift Insert pastes block of text from the clipboard to where the cursor is while in editing (insert) mode.
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | page 11