Wednesday, June 20, 2012

GVIM BASICS & TIP & TRICKS -2 short tutorial

This article is in continuation from my last article gvim-basics-tip-tricks-1. The best thing with GVIM is that each day you get to learn something new and useful to learn.

So more tips and tricks:
1) * : "*" is used to search word near/under your cursor.

2) %: "%" can be used to look for accompanying bracket. {},[],(). For example if your cursor is on "{" and you press "%" the it will take you to the corresponding "}". It can be very useful when used with "d"(delete) or "y"(yank).

3)"q:"- "q:" is used to view your command history, you can copy paste commands from there or even edit the commands and run the commands directly by selecting them.

4)"q/" - used view previous searches.

5) If you like colors then you can put on the color font by ":syntax on" or just put "syntax on" in your .vimrc file and this action will be taken every time you open a new vim window.

6) w! - sometimes when you try to edit write protected file ":w!" can be useful .

7) :wq! - save and exit write protected file.

I will share some tips and tricks here and keep on writing new articles as I learn more.

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"

Saturday, June 9, 2012

HOW "VIM" IS THE KING OF ALL IDE's

I used "source insight" for more than 15 months and I just loved the tool and just cannot imagine writing a code without it but then my life changed a little bit and I have to start working on a red hat machine so no source insight.

At start I found it to be very difficult to survive without it but later on doing some search over Internet I found some tools which can save my life while coding on Linux . Some of those life saver tools were cscope, Ctags, etc but the tool on which all these work the king of all Vi/VIM/GVIM. After 6 months of work on gvim now I no longer miss source insight.

The learning curve on vim is quite steep there are loads of stuff you can do on it which you a cannot think of doing on any other IDE. The Internet is full with the tutorials and tips and tricks for these tools. It just took me few weeks to be comfortable with them and use them flawlessly.

So I think I will write an article on tips and tricks I use on vim a collection of all the tricks I accumulate in last 5-6 months. Will try to do that in coming days keep looking for that in this space.


A word of caution for all those who are looking forward to using these awesome tools they are very addictive. Nowadays even when I try to save my MS word doc I try to do it with ":w"(all those who use vim will get the joke ;) )........


Do leave comments about how you feel about these wonderful tools ... Thanks