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.
Showing posts with label VIM. Show all posts
Showing posts with label VIM. Show all posts
Wednesday, June 20, 2012
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"
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
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
Monday, May 7, 2012
Replacement for source insight in Linux
Few days back I changed my job. In my last job I used to work on windows machine and used source insight as my default IDE. In my new job I work on Red hat machine so have no "source insight". First few days I spent on google to find a replacement . So I think it's a good idea to share all the information I got....
1) cscope : a nice tool for exploring large codes ... You just need to save all the files in the project to the file "cscope.files" ... To do this run the following command at the to directory of your code base :
"find ./ -name "*.c">cscope.files"
"find ./ -name "*.h">>cscope.files"
....
And similar command for all the file extension you have in your project .
Finally type command "cscope" and you are ready to go ... It will show you options like find C symbol ,global definition ,find string,replace string, ... And a few more .. Although it is not a complete replacement for "source insight" but you get used to it in long run ..
2) Ctags/tags : this option can be used with vim just prepare the tags file and there you go now of you want to jump to definition of any function/variable/constant/structure .. Just keep cursor over the function and press cntrl+t .. Press cntrl+] to return .. If you are using GVIM then its even more simple . press cntrl+left-click to go to tag press cntrl+right-click to return.
3) use Eclipse ... Although I have not personally used it but have heard that they have a package for Linux also ..
4) finally if you know the code well and do not need frequent searching .. Then you can survive with emacs/vi/vim/gvim. Actually these are one of the best IDE's if you can master them. Learning curve for vim is quite steep and same goes with emacs. All i can say is that these are very powerful tools only in the right hands. There are a loads of stuff you can do with these tools quite easily which you cannot think of doing with other IDE's.
If you are working on Linux and use different IDE for code browsing ..comments are most welcome
1) cscope : a nice tool for exploring large codes ... You just need to save all the files in the project to the file "cscope.files" ... To do this run the following command at the to directory of your code base :
"find ./ -name "*.c">cscope.files"
"find ./ -name "*.h">>cscope.files"
....
And similar command for all the file extension you have in your project .
Finally type command "cscope" and you are ready to go ... It will show you options like find C symbol ,global definition ,find string,replace string, ... And a few more .. Although it is not a complete replacement for "source insight" but you get used to it in long run ..
2) Ctags/tags : this option can be used with vim just prepare the tags file and there you go now of you want to jump to definition of any function/variable/constant/structure .. Just keep cursor over the function and press cntrl+t .. Press cntrl+] to return .. If you are using GVIM then its even more simple . press cntrl+left-click to go to tag press cntrl+right-click to return.
3) use Eclipse ... Although I have not personally used it but have heard that they have a package for Linux also ..
4) finally if you know the code well and do not need frequent searching .. Then you can survive with emacs/vi/vim/gvim. Actually these are one of the best IDE's if you can master them. Learning curve for vim is quite steep and same goes with emacs. All i can say is that these are very powerful tools only in the right hands. There are a loads of stuff you can do with these tools quite easily which you cannot think of doing with other IDE's.
If you are working on Linux and use different IDE for code browsing ..comments are most welcome
Subscribe to:
Posts (Atom)