Vi: Difference between revisions

135 bytes removed ,  6 years ago
Line 37:
;Executing a filter command
 
# ‘!’ symbol is used within the command line of Vi editor to execute an external program.
# The line number 1 and the $ symbol in the above command can be replaced with any portion of the file with the numbers of the starting line and ending line of the particular portion.
 
*To sort the file from the first line to the last line
Line 55:
:10,20 ! tr a-z A-Z
 
*Writing a portion of file, lines from 20 to 50 to a new file beingnamed editednewfile.txt:
:20,50 w > newfile.txt
 
As a result, the lines from 20 to 50 are written in a new file named newfile.txt.
The above facility of processing parts of the text and substituting the original content with the output makes the Vi editor very powerful.
 
;Inserting the output of a command executed within the Vi editor
Line 71 ⟶ 68:
*Cursor movements
 
H The cursor is positioned at the first line of the screen
M The cursor is positioned at the middle line of the screen
L The cursor is positioned at the last line of the screen
 
*Scrolling through a file
Ctrl-f Scroll down by one screen
Ctrl-b Scroll up by one screen
Ctrl-u Scroll up by half a screen
Ctlr-d Scroll down by half a screen
zz Scroll the screen so that the current line appears at the middle of the screen, very useful for viewing the block of code associated with the current line.
 
*Editing a file opened without sudo
Line 87 ⟶ 84:
 
*Powerful delete commands
di( Deletes all characters within the parentheses
di” Deletes all characters within the quotes
 
*Recovering a file, after a crash, from the swap file of the file being edited: