Friday, June 15, 2012

GVIM BASICS & TIP & TRICKS -1 short tutorial

As I mentioned in my last post I have been working on GVIM for past few months and each day I am surprised by some new capabilities of the tool. I will share some tips and tricks here and keep on writing new articles as i learn more.

Some basics:

1) Save your file with ":w"
2) Exit with ":q"
3) Start writing/inserting text : "i"
4) copy a line: "y"
5) paste the copied line : "p"
6) Save and exit with ":wq"
7) Undo : "u"
8) Redo: "ctrl+r"
9) Search:  use "?" or "/" followed by string to search use "n" for next match.
10) Replace: use ":%s/str1/str2/g" to replace str1 to str2 globally ":%s/str1/str2/gc" will confirm before replacing.
11) To add "tab" before each line select the lines and then press">".
12) ":g/str/g": This command will delete the lines containing string "str"
13) To display line numbers : ":set nu"
14) To turn of display of line numbers : ":set nu!"
15) ":help" : To open help file.
16) ":set ic" :  after this command all the searches will be case insensitive.
17) ":set noic" : after this command all the searches will be case sensitive.

Tricks:
1) In all the command when you give strings and if your string contains special characters (#$@^&\/) then just add "\" befor the special character.
eg: in order to search for "a/b/c" the command should be "/\/a\/b\/c"

2) you can have a .gvimrc file in your home directory in which you can write all the set commands like ":set nu" and all the other commands listed up. GVIM will read the file every-time it starts and will apply the settings.

3) Type "/" and keep on pressing ctrl+p to find what was your previous searches.

4) If you want to delete next 10 lines, then in normal mode type "10dd", for 5 -"5dd"  so trick is <number>dd, same can be done for yank(copy) "<number>yy"

No comments:

Post a Comment