TKServer

VI Command Mode - Editing Text Files in Linux

VI Command Mode - Editing Text Files in Linux

Reference

VI COMMAND MODE INSTRUCTIONS
File Saving
ZZ or :wq Save the file and exit vi
:w Save the file
:q This quits the current file, but only if there are no unsaved changes
:q! The get-me-out-of-here! command, this quits vi without saving, so all changes are lost
Navigating Text
Arrow keys Move the cursor around the document
h(left), l(right), j(down), k(up) Alternatives to the arrow keys
w Moves the cursor to the beginning of the next word
b Moves the cursor to the beginning of the previous word
0 (zero) Moves the cursor to the beginning of the current line
$ Moves the cursor to the end of the current line
H Moves the cursor to the beginning of the first line currently on the screen
M Moves the cursor to the beginning of the middle line currently on the screen
L Moves the cursor to the beginning of the last line currently on the screen
Ctrl+f Go forward one page
Ctrl+b Go back one page
Ctrl+d Go forward half a page
Ctrl+u Go back half a page
G Go to the last line of the file
#G Move the cursor to the line number specified by #
Deleting text
x Deletes the character under the cursor
X Deletes the character before the cursor
dw Deletes from the current character to the end of the current word
d$ Deletes from the current character to the end of the current line
d0 Deletes from the current character to the beginning of the current line
Search and Replace
/text Search the file forward from the current cursor position for the text specified
?text Search the file backward from the current cursor position for the text specified
/some.*text Using regular expression-like wildcards, this will search for a line that contains the character string some followed by, after any intervening characters, the character string text
?[tT]ext Searches backwards for text or Text - remember that searches are case sensitive
:g/text Prints every line in the file that contains text
:s/text/replacement Replaces text with replacement on the current line
:g/text/s//replacement/g Replaces text with replacement in the entire file
:g/text/s//replacement/gp Replaces text with replacement in the entire file and displays the changes made onscreen
Written by Administrator