Wednesday, June 18, 2014

VI Editor Commands in Linux

Vi editor commands

Input commands with (esc or ESCape)

Appends after cursor
Inserts before cursor
Opens a new line below the cursor
Opens a new line above the cursor
Deletes single word
Deletes entire line
Undo last change
Undo all changes of single line
-yy- or -Y-
Copies single line
Copies 5 lines
Deletes 5 lines
Paste the line after the cursor
Paste the line before the cursor
Deletes a character
Saves file with the given name
Save and exit from vi
Quit without save
Same as wq
Goto last line
Goto specified line number
Displays current line number and file information
Searches for a string in the file
Repeats the search towards down (Find Next)
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
Replace only in current line, If you include %infront of s it replaces all lines


No comments: