1.Basic vim commands
i.vim vim.txt => open file in vim
ii. :q => quit
iii. :q! => force quit
IV. :wq or ZZ => save and exit
V. :x => save and exit ,if only changes happen.
Esc (exit the current mode and return to normal mode) --> escape the mode
2.Modes in Vim:-
I. Normal Mode => Default mode (navigate and edit,delete , modifying ..etc) ,vim the default mode when open a file is Normal file.
II. Insert Mode => insert and edit the text => press i .
III. Command Mode => Execute the commands followed by : command.
IV. Visual mode => select text v for character-wise, V for line-wise.
3.Navigation Commands (Normal Mode):-
I. h => move left
II. l => move right
III.j => move down
Iv. k => move up
V. 0 => move the beginning of the file.
VI. ^ => move to first non-blank character of the line.
VII. $ => move to end of line
VIII. gg => go to beginning file
IX. G => go to end of file
X. nG => go to exact number line
example:
press any number and G , cursor move exact number line
Xi. Ctrl + d => scroll half-page down
XII. Ctrl + u => scroll half-page up
XIII. Ctrl + f = >scroll full-page down
XIV. Ctrl + b => scroll full-page up
4.Insert Mode:-
I. i => insert at cursor position
II. I => insert at beginning of line
III a => Append after cursor
IV A => Append at end of line.
"append" means adding text after the cursor
V o =>open a new line below the current line.
VI O =>open a new line Above the current line.
5.Deleting & cutting Text:-
I. x => Delete character under cursor
II. dw => Delete word
III. dd => delete entire line,3dd
IV. d0 => Delete from cursor to beginning of line
V. d$ or D => Delete from cursor to end of line
VI. dG => Delete from cursor to end of file
VII. :1,.d =>Delete from line 1 to current line
VIII. :.,$d => Delete from current line to end of file.
IX.
6.Copy & paste:-
I. yy => copy current line,3yy
II.y$ =>copy to end of line
III. yw => copy word
IV. yG => copy current cursor to end of file
V. p =>Paste after cursor
VI. P => paste before cursor.
VII. cc => deletes the entire line and enters insert mode, dd+i=c.
7.Undo & Redo:-
I. u +> undo last change
II. ctrl + r => Redo the last undone change
8.searching:-
I. /word => search for word forward ,after enter press n =same direction, press N =opposite direction
II. ?word => search for word backward ,after enter press n =same direction, press N =opposite direction
III. :%s/oldword/new_word/g => Replace all occurrences of old with new
IV.:%s/oldword/new_word/gc => Replace with confirmation
8.Important Vim option for productivity:-
I. :set number => show line number
II. :set nonumber => Hide line numbers
III.:set autoindent/:set noautoindent (தானாக உள்தள்ளல்) => Enable auto-indent
Now, when you press Enter in Insert mode, Vim will automatically indent the next line.
example:-
int x =10;
int y =20;( auto indent)
when you press Enter , the next line will start with same spaces
IV. :set tabstop=4
after executed ,when press tab key ,vim use 4 spaces
V. :set ignorgcase
after executed, when use to searching /,it do not care about uppercases and lowercase
VI. :set hlsearch
after executed, when use to searching /,highlighted the words
10.Working with multiple files:-
After opened file:-
I. :e filename => open another file
II. :bn => swith to next file
III. :bp => switch to previous file
IV. :bd => close current file
V. :sp => split screen and open file
VI. :vsp => verticular split screen
VII. :tabenew filename => open file in a new tab
VIII. :gt => go to next tab
IX. :gT => go to previous tab
X. :tabclose => close current tab
XI. :tabonly => close other all tabs except current.
XII. ctr + w + w => switch b/w splits.(works in both horizontal & vertical splits).