frequently used vi

Frequntly used VI/GVIM commands:
1. Online VI editor: Use this online Vi editor to practice vi commands.
-------------------------------------------------------------------------------------------
2. Search and replace:
:%s/searchword/replaceword/  takes care of one occurence of searchword in a line.
:%s/searchword/replaceword/g takes care of all occurences of searchword in a line.
-------------------------------------------------------------------------------------------
3. To delete all lines which contains the text "word"
:g/word/d
:g/word1 word2/d
This command tells vi to do a global search for "word word1" and to delete any line containing that text including the space.
-------------------------------------------------------------------------------------------
4. How to indent multiple lines in Vim
  • Open up a text file in Vim that needs indenting.
  • On the line that you want to start your indenting block type: '=='(This will indent the first line).
  • Press the 'v' key to go into visual mode.
  • Move the cursor down to select the number of lines you want to indent.
  • Press '=' to indent the selected cells.
  • As you can see that was the last step, and all your selected lines are indented.
-------------------------------------------------------------------------------------------
5. Using vi, you can issue global commands from command mode. If you are not sure of the case used, you can issue this command from vi command mode before you make the global change:
:set ic
(set ignorecase)
-------------------------------------------------------------------------------------------
6.
:%s/\'.*$//g

-------------------------------------------------------------------------------------------
7. Macros
qa /F_POS_LO <enter> ^i // <ESC> q
-------------------------------------------------------------------------------------------
8. To do an operation between two lines
 -------------------------------------------------------------------------------------------

9. vi delete multiline comment
\/\*[a-z0-9A-Z_; ]*\_[a-zA-Z0-9;_ ]*\*\/

:set ic
(set ignorecase) 

revrse a file
tac
tail -r filename

No comments:

Post a Comment