Wednesday, June 18, 2014

VI Editor Commands in Linux



Vi editor commands


Input commands with (esc or ESCape)

Character
Description
-a-  
Appends after cursor
-i-
Inserts before cursor
-o-
Opens a new line below the cursor
-O-
Opens a new line above the cursor
-dw-
Deletes single word
-dd-
Deletes entire line
-u-
Undo last change
-U-
Undo all changes of single line
-yy- or -Y-
Copies single line
5yy
Copies 5 lines
5dd
Deletes 5 lines
-p-
Paste the line after the cursor
-P-
Paste the line before the cursor
-x-
Deletes a character
:w
Saves file with the given name
:wq
Save and exit from vi
:q!
Quit without save
ZZ
Same as wq
G
Goto last line
6G
Goto specified line number
Ctrl+g
Displays current line number and file information
/searchstring
Searches for a string in the file
-n-
Repeats the search towards down (Find Next)
-N-
Repeats the search towards up (Find Previous)
:set list
Show invisible characters
:set nolist
Don’t show invisible characters
:set number
Displays line numbers
:set nonumber
Line numbers off
:set ignorecase
Ignore the case (helps while searching for a string in the file)
:set noignorecase
Switch off the ignore case option
:%s/Historical/historical_new /g   
Replaces string Historical to historical_new
% -  All lines
/g  - Replace all occurrences in all lines
:5,20s/kalyan/kalyan_new /g
Replaces string from 5 to 20 lines only
:%s/SearchString/Replacewith /gi
-gi - Indicates replace string globally ignores case
:s/Linux/Unix
Replace only in current line, If you include %infront of s it replaces all lines


 

No comments: