Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » VIM + Code::blocks

Credits go to ReyBrujo for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
VIM + Code::blocks
FMC
Member #4,431
March 2004
avatar

I've recently started using Vim and i have to say i find myself extremely well, it really is an extremely powerfull editing tool.

One thing i miss is the context sensitive autocompletion you get in modern IDEs.
If, for example, i have a class object called weapon i can do weapon. and the IDE will suggest its public methods.

I know a Vim plugin exists for Visual Studio, so i'd think there was also one for Code::Blocks but i can't find it.

Does anybody know of such plugin, or of another free IDE well integrated with WIM?

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

OICW
Member #4,069
November 2003
avatar

The question is why don't to use pure Code::Blocks. What exactly is so special about editor with weird keyboard shortcuts and unintuitive contorls (my personal view). On the other hand I'd like to learn a bit more, so I could copy/paste text in it.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

FMC
Member #4,431
March 2004
avatar

Controls indeed are unintuive, the fact is that after you learn them, editing gets much faster and "fun". Yes, fun! :P

Seriously, give a try with a good tutorial/book (or simply at the help files), you'll be amazed by it's power!

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

OICW
Member #4,069
November 2003
avatar

That would be a problem, since I despise by books about some common programs like a text editor. Hopefully I'll learn more about Vim as my Introduction to UNIX operating systems continues. And by experimenting with it at home. Nonetheless I still prefer to use Code::Blocks for larger projects and Kate for smaller ones.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

FMC
Member #4,431
March 2004
avatar

In the meantime, have a look at this: http://www.viemu.com/a-why-vi-vim.html

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

OICW
Member #4,069
November 2003
avatar

Well that's the first time I have seen some examples of what it can do. I'm quite impressed by it's complexity, but one thing remains in my head: "how the heck I'm supposed to remeber it?"

I mean that if I'm going to learn it right now, I'll end up with month of suffering with memorizing new commands and doing really nothing.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

ReyBrujo
Moderator
January 2001
avatar

Quote:

One thing i miss is the context sensitive autocompletion you get in modern IDEs.
If, for example, i have a class object called weapon i can do weapon. and the IDE will suggest its public methods.

You have three ways of autocompleting. The first one is just CTRL-N and CTRL-P in insert mode, that will cycle through all the words in source files beginning with the current text. The second is omni completion (Vim 7 or superior), you use CTRL-X N and CTRL-X P to cycle through words in intellisense mode after turning it on. The third one is using the taglist plugin. You will need to install the plugin (copying it to $VIM/plugins), installing ctags (an executable) and executing a couple of commands to build the tags. This is the closest to intellisense you can get (omni will be in the future since it is natively supported, but it is being worked still).

Here is an image of taglist:
{"name":"taglist_c.gif","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/8\/584f0e5d7aaa33e618fd779bcb4ba385.gif","w":934,"h":718,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/8\/584f0e5d7aaa33e618fd779bcb4ba385"}taglist_c.gif

(Edited: If you are using Vim 7 or superior, check OmniCppComplete, I tried it out and works pretty well. It works like taglist (you install the plugin and run ctags to generate the tags), but it uses omni to present the options. Here is how it looks in one of my projects:

I am wanting to check pShop members:
{"name":"594642","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/a\/fa7aec1f299d4a54cc0b33bbed070a10.png","w":665,"h":433,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/a\/fa7aec1f299d4a54cc0b33bbed070a10"}594642

After a . or ->, the omni completion triggers in:
{"name":"594643","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/3\/a3a59d755aba4ba7806ab95377b8e037.png","w":665,"h":433,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/3\/a3a59d755aba4ba7806ab95377b8e037"}594643

If you begin browsing (with down or up) a buffer opens with the information about the function:
{"name":"594644","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/3\/d3856440282fcc50e04f309e4522c7e8.png","w":665,"h":433,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/3\/d3856440282fcc50e04f309e4522c7e8"}594644

Even though it is not complete, it is very usable, and it even shows inherited methods).

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

alethiophile
Member #9,349
December 2007
avatar

I hereby resolve not to post in this thread anymore.

I use Emacs. ;D

--
Do not meddle in the affairs of dragons, for you are crunchy and taste good with ketchup.
C++: An octopus made by nailing extra legs onto a dog.
I am the Lightning-Struck Penguin of Doom.

FMC
Member #4,431
March 2004
avatar

Quote:

The first one is just CTRL-N and CTRL-P in insert mode, that will cycle through all the words in source files beginning with the current text.

Knew about this one, but it isn't "smart" enough. :)

Quote:

The second is omni completion (Vim 7 or superior), you use CTRL-X N and CTRL-X P to cycle through words in intellisense mode after turning it on

Didn't know of this one, but after some reading it seems it is:
a) C only
b) not very capable of parsing source files

the manual said:

Vim doesn't include a C compiler, only the most obviously formatted
declarations are recognized. Preprocessor stuff may cause confusion.
When the same structure name appears in multiple places all possible members
are included



Option 3:

Quote:

The third one is using the taglist [vim-taglist.sourceforge.net] plugin. You will need to install the plugin (copying it to $VIM/plugins), installing ctags (an executable) and executing a couple of commands to build the tags.

Quote:

(Edited: If you are using Vim 7 or superior, check OmniCppComplete [vim.org], I tried it out and works pretty well. It works like taglist (you install the plugin and run ctags to generate the tags), but it uses omni to present the options. Here is how it looks in one of my projects:

I'm working on this (nobody said Vim&Co where easy ;)), but while i'm sorting out the various config changes, i have a question:
is it able to parse external files? I mean, if i'm working on game.cpp and try to use a Sprite (a class defined in sprite.cpp) method, will OmniCppComplete be able to understand that what i'm asking is in another file?

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

ReyBrujo
Moderator
January 2001
avatar

Quote:

is it able to parse external files? I mean, if i'm working on game.cpp and try to use a Sprite (a class defined in sprite.cpp) method, will OmniCppComplete be able to understand that what i'm asking is in another file?

If you ctags the files, of course. Check my third screenshot: I am working on CTest.cpp, and omni is showing me methods defined in Shop.h and the ones CShop inherited from Object.h.

The only bad thing is that you need to ctags the files to update. It is not difficult if you set a map to call ctags, and call it every time you add a new method, but it is still not automatic.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

FMC
Member #4,431
March 2004
avatar

Quote:

The only bad thing is that you need to ctags the files to update. It is not difficult if you set a map to call ctags, and call it every time you add a new method, but it is still not automatic.

You mean i assign a hotkey from Vim to ctags and call it whenever i edit a file, to keep up to date its tags?
Of course i'd also have to assign each file of the project to ctags, right?

Anyway, it seems this is what i was asking for, cookies to you! :)

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

ReyBrujo
Moderator
January 2001
avatar

Nah, you just ctag the directories you want parsed. I use .. when I am editing within src/ so that it parses ../src (the current directory) and ../include (the include one).

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

FMC
Member #4,431
March 2004
avatar

Cool, i got it sortof working! :)

in my _wimrc file i have
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

set nocp
filetype plugin on

...and it automagically works!

The only annoying thing is to have to Ctrl-F12 every time i change a class, it's especially annoying because it opens a window which has to then be closed.

Now i just have to finetune a few things...

[EDIT]Btw how would i go to tag the whole standard library? Run ctags in the include directory of my compiler, and then append to that tag file?

[EDIT2]THe manual says to use C-X, C-O (after . or ->) to use the autocompletion, but while C-O moves down the list, C-X doesn't seem to do anything usefull... any ideas?

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

bamccaig
Member #7,536
July 2006
avatar

ReyBrujo
Moderator
January 2001
avatar

Quote:

The only annoying thing is to have to Ctrl-F12 every time i change a class,

Told you so ;) In theory, you could expand that macro to map <C-F12> :w<CR> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR> so that it saves and execute ctags automatically.

Quote:

it's especially annoying because it opens a window which has to then be closed.

That is strange, in Linux there is no such window. I am guessing it is a command prompt? I will try it at work (I have 6.3 installed there still, though).

Quote:

[EDIT]Btw how would i go to tag the whole standard library? Run ctags in the include directory of my compiler, and then append to that tag file?

Yep! Since they don't likely change, run it once, generate a tags file, and put it somewhere, then set the tags parameter to point to that file at the beginning. In Linux, I ctag /usr/include and /usr/local/include, keep the file at ~/.vim/stdtags, and then in the .vimrc file I add set tags=~/.vim/stdtags,tags,.tags,../tags. My stdtags file is 44mb.

Here is a screenshot when using the ios namespace:
http://www.allegro.cc/files/attachment/594651

Quote:

THe manual says to use C-X, C-O (after . or ->) to use the autocompletion, but while C-O moves down the list, C-X doesn't seem to do anything usefull... any ideas?

CTRL-X is a meta key for an omni command (just like Emacs). So, CTRL-X tells Vim you are going to use an omni command. There are so many that Vim has started to use pairs of commands. If you type C-X twice, you will get the context help for all the possible combinations (^]^D^E^F... etc). C-X C-O is the easiest way to trigger omni when you have already dismissed it (say, you wrote test-> and pressed ESC, and want to get the list of members again: instead of deleting -> and typing it again, just press C-X C-O). It is also used for namespace completion, which is not automatic. So, you can write ios:: and omni won't trigger. To do that, you need to press CTRL-X CTRL-O (which is what I typed to get the screenshot above, then I wrote "left").

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

FMC
Member #4,431
March 2004
avatar

Quote:

That is strange, in Linux there is no such window. I am guessing it is a command prompt? I will try it at work (I have 6.3 installed there still, though).

Yep, the "Press a key to continue" type.

Quote:

Told you so In theory, you could expand that macro to map <C-F12> :w<CR> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR> so that it saves and execute ctags automatically.

Good idea. :)

Quote:

Yep! Since they don't likely change, run it once, generate a tags file, and put it somewhere, then set the tags parameter to point to that file at the beginning. In Linux, I ctag /usr/include and /usr/local/include, keep the file at ~/.vim/stdtags, and then in the .vimrc file I add set tags=~/.vim/stdtags,tags,.tags,../tags. My stdtags file is 44mb.

So, the last line means that Vim will check the tags in vim/stdtags, the tags file in the current and upper directory, and in a file called .tags(in the current dir) - Am i right?

Quote:

CTRL-X is a meta key for an omni command (just like Emacs). So, CTRL-X tells Vim you are going to use an omni command. There are so many that Vim has started to use pairs of commands. If you type C-X twice, you will get the context help for all the possible combinations (^]^D^E^F... etc). C-X C-O is the easiest way to trigger omni when you have already dismissed it (say, you wrote test-> and pressed ESC, and want to get the list of members again: instead of deleting -> and typing it again, just press C-X C-O). It is also used for namespace completion, which is not automatic. So, you can write ios:: and omni won't trigger. To do that, you need to press CTRL-X CTRL-O (which is what I typed to get the screenshot above, then I wrote "left").

Ah, good to know.
Vim is amazing, the more i use it, the more i discover about it, the more i'm amazed by its complexity, the more it makes me feel a little ignorant, so much to learn!

Btw, thanks for everything, you're being most polite and useful!

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

ReyBrujo
Moderator
January 2001
avatar

Quote:

Yep, the "Press a key to continue" type.

Ah, that one. I don't really care, but if you do, just add an extra <CR> at the end of the map so that it saves you from doing it yourself.

Quote:

So, the last line means that Vim will check the tags in vim/stdtags, the tags file in the current and upper directory, and in a file called .tags(in the current dir) - Am i right?

Correction: the tags in .vim/stdtags (it is a hidden directory).

Yep. It is a list of files it needs to check (just as path gives a list of paths in which it will search when searching for files when you do CTRL-W CTRL-I on top of a class or type.

And hey! If Stallman can spread the gospel about Emacs, why I can't do the same for Vim ;)

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

FMC
Member #4,431
March 2004
avatar

Quote:

Ah, that one. I don't really care, but if you do, just add an extra <CR> at the end of the map so that it saves you from doing it yourself.

Doesn't work (under winxp). :(

Another question, how do you manage your project files? In an IDE you have them all lined up on a list somewhere on the screen, how do you switch between files with Vim? Call the file with the :!vim file.ccp syntax?

Quote:

And hey! If Stallman can spread the gospel about Emacs, why I can't do the same for Vim

I don't see why you shouldn't... ;)

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

ReyBrujo
Moderator
January 2001
avatar

Quote:

Doesn't work (under winxp)

Hmm... strange... I will see if it happens on Windows 2000 too... it works fine under Linux.

Quote:

Another question, how do you manage your project files? In an IDE you have them all lined up on a list somewhere on the screen, how do you switch between files with Vim? Call the file with the :!vim file.ccp syntax?

There are some plugins that give you a project-like manager, but I prefer doing that manually. There is a key combination to open the header you are currently indicating with the cursor, but I prefer doing that myself.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

bamccaig
Member #7,536
July 2006
avatar

This thread has me really interested in vi/vim. :D This was really good to experience. Now I'm interested in finding tutorials for vi/vim. But where will I find the time? :-/

ReyBrujo
Moderator
January 2001
avatar

Quote:

Doesn't work (under winxp).

Ah, I noticed what you mean. Under Linux it does not open a new console, just creates a new thread and runs it. Under Windows, it opens a new console forcefully. I am guessing there is a way to compile vimrun.exe to not open the window. For the time being, though, try :map <C-F12> :w<CR>:!start ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> (note that you will need the two CR at the end to prevent what commonly happens under Linux: the "Press ENTER or type command to continue" prompt in the Vim editor. Not elegant, but apparently works fine enough (get sure it can execute ctags by putting it in your path, or by using full path in the map).

Quote:

This thread has me really interested in vi/vim. :D This was really good to experience. Now I'm interested in finding tutorials for vi/vim. But where will I find the time? :-/

When you install Vim it should create a "tutor" directory (C:\Program Files\Vim\vim71\tutor or similar in Windows). Make a copy of it, and edit the "tutor" file inside the directory (so you don't lose the original tutorial) and spend some time reading it. When I started (Vim 5 wasn't released yet) there was a one-file tutorial which was pretty cool (it basically said what I said somewhere else about deleting several lines with a command, etc). I am guessing the new tutorial is much better.

Time is another problem, though.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

bamccaig
Member #7,536
July 2006
avatar

I installed Vim in Windows a few months ago, but I haven't really used it much... I guess now is my opportunity.

FMC
Member #4,431
March 2004
avatar

Quote:

When you install Vim it should create a "tutor" directory (C:\Program Files\Vim\vim71\tutor or similar in Windows). Make a copy of it, and edit the "tutor" file inside the directory (so you don't lose the original tutorial) and spend some time reading it. When I started (Vim 5 wasn't released yet) there was a one-file tutorial which was pretty cool (it basically said what I said somewhere else about deleting several lines with a command, etc). I am guessing the new tutorial is much better.

Actually now there is a vimtutor.bat which will set up the tutorial for you, without even having to make a copy of the tutorial file. :)

Quote:

Ah, I noticed what you mean. Under Linux it does not open a new console, just creates a new thread and runs it. Under Windows, it opens a new console forcefully. I am guessing there is a way to compile vimrun.exe to not open the window. For the time being, though, try :map <C-F12> :w<CR>:!start ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> (note that you will need the two CR at the end to prevent what commonly happens under Linux: the "Press ENTER or type command to continue" prompt in the Vim editor. Not elegant, but apparently works fine enough (get sure it can execute ctags by putting it in your path, or by using full path in the map).

I love you! :-*:D

[edit]

Quote:

Now I'm interested in finding tutorials for vi/vim

Believe me, the Vim help file have more information than you can possibly read in a few days. :P

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

GullRaDriel
Member #3,861
September 2003
avatar

Heh, mind what, I have just achieved to make my boss agreeing with the fact we should upgrade vim on our sun servers and that it could be a nice thing to install code completion for all users too ;-p

Thanks Rey for the link !

Vim FTW !!

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

ReyBrujo
Moderator
January 2001
avatar

Quote:

Actually now there is a vimtutor.bat which will set up the tutorial for you, without even having to make a copy of the tutorial file. :)

Ah, didn't notice that. Linux has a vimtutor, but didn't think they would add it to the Windows release.

(Edited: Oh, I forgot to mention Vim Intellisense. I used to test it out, worked very well and had Visual Studio-like intellisense. However, I dismissed it years ago because I cannot use it at home (Windows only). You may want to check it out too:

{"name":"vis_help.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/b\/6be419ea14bf3061fc60fd222c2b67b0.jpg","w":727,"h":363,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/b\/6be419ea14bf3061fc60fd222c2b67b0"}vis_help.jpg

It is inactive right now, as they could not port it to Linux, and with the new omni it may become obsolete in future releases. Still, it pretty good (although a little slow when popping the help information)

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

 1   2 


Go to: