VIM editor series I

Search A Pattern

  • Press Esc
  • Then type / or ? and the pattern need to search

To do Substitution

:%s/Old String/New String/g 

Converting the Tab to Spaces

:set expandtab 


To control the number of space character need to be inserted when the tab was used

:set tabstop=4 

After the expandtab option is set all the new tab characters entered will be changed to spaces. This will not affect the exiting tab characters. To change all the existing tab characters to match the current tab settings use

:retab 

Display the line numbers
enable the line number

:set number or :set nu 

disable the line numbers

:set nonumber or :set nonu 

Reversing the Order of lines

:g/^/m0


:—- start the command line mode
g—- action will be taken all lines in the files
^—-matches the starting of the line
m—moves the elements
0—Is the destination line, beginning of the buffer

If i need to reverse the lines between a certain range(like between 30 and 40 lines), then we can use the following command

:30,40g/^/m29 

To control the position of split window

:set splitbelow or splitright 

Undo and Redo
        In normal mode conditions

  • use u for undo the action
  • cntrl+r for redo the action        

Comments