Friday, August 27, 2010

Vi commands .... which make life easy !!

Here I will put some really handy vi short-cuts. I am putting only those vi commands which a newbie can remember quickly and start using vi from now-onwards.

Note: Do not forget to press "Esc" first and the start following commands.

1) [n]dd :: Pressing 'dd' will cut the current line. If you press say '2dd' it will cut two lines.

2) [n]yy :: Pressing 'yy' will copy the current line. If you press say '2yy' it will copy two lines.

3) p :: Pressing 'p' (small p) will paste the copied/cut line(s) starting from the next line with respect to cursor.

4) [n]<< :: Pressing '<<' will shift current line by one tab. If you press say '2<<' it will shift the two lines counting from the current line(inclusive).

5) [n]>> :: Same as '4' but it will shift right.

6) /guru :: Pressing '/' then typing the text to search will search the text you have typed. But this search is case sensitive.

7) :set ignorecase :: To make you search case insensitive. Now onward you all searches will be case insensitive.

8) :set noignorecase :: To reset the '7' to case sensitive.

9) uu :: Pressing 'uu' will undo you last change. But if you keep pressing 'uu' several times it will keep redoing in reverse order of changes you have made.

10) Ctrl + r :: Pressing 'Ctrl+r' will do redo work for you.

11) ZZ :: Pressing 'ZZ' is same as ':wq'

12) D :: Pressing 'D' will delete current line starting from the cursor position to end of line. All text behind the cursor will remain as it is.

13) R :: Pressing 'R' will take you into replace mode. Meaning if you type over some text it will replace that text with letters you have typed.


Keywords:: vi cheats, vim cheats, vi commands, vi commands cheat sheet

1 comment: