0

I want to set Vim to work with C++, I just want to perform these tasks:

  • write code (you don't say?)
  • check and highlight C++ syntaxis
  • autocompletion (if is possible)
  • compile, run, debugging and return to the editor
  • tree-view project files on the side
  • statusbar

I know that much of this tasks can be done with plugins, so I need your help to make a list of required plugins and how to set them up together.

why basic? well, I'm taking the programming course level 1 in my university, and we will make simple command-line programs, simple such a mathematical evaluations (functions, array even or odd numbers, draw triangles with asterisks and so.)

mao2047
  • 91
  • 1
  • 8
  • 1
    It's not a valid SO question. (Off topic maybe) – masoud Aug 24 '13 at 07:09
  • Vim is not an IDE. Why in the world would you cripple your productivity by programming in vim instead of an _actual_ IDE? For Linux I advise Qt Creator. – Violet Giraffe Aug 24 '13 at 07:09
  • You might consider emacs. It'll allow to you write code, compile, debug. Even has a shell mode! – devnull Aug 24 '13 at 07:12
  • ok, I know that vim _is not_ a real IDE, but I just will write simple command-line programs, why a potent IDE, I don't want to go out from the terminal. – mao2047 Aug 24 '13 at 07:13
  • @shuuichi_nitori: don't want debugging? What kind of programming is that? And even simple code editing is slower in vim. – Violet Giraffe Aug 24 '13 at 07:17
  • @Violet: none of your claim makes sense to me. – László Papp Aug 24 '13 at 07:26
  • @LaszloPapp: that's a very informative reply, I've learned a lot. Thanks. P. S. Similarly, encouraging counter-productive behavior doesn't make sense to me. – Violet Giraffe Aug 24 '13 at 07:34
  • @VioletGiraffe: do we really need to tell printf for debugging, or even that many people use vim for C++ stuff as an "IDE"? Please do not start such flamish stuff with newcomers. Be productive here, and try to help. If you have no clue, just stay away. – László Papp Aug 24 '13 at 07:37
  • @LaszloPapp: newcomers should know better than using 30 years old tools that have so much more elaborate modern analogs. – Violet Giraffe Aug 24 '13 at 07:40
  • @VioletGiraffe: for your personal taste, maybe... Please do not start flame ways. Check the SO policy please, and stay on topic. Help with the flavor at question, or stay away. Thanks. – László Papp Aug 24 '13 at 07:41
  • @M M. it is not off-topic as it is related to a programming tool which is on topic in here. – László Papp Aug 24 '13 at 07:46
  • @VioletGiraffe simple code editing is slower in vim?? That is a rather bizarre statement. Of course, it is true if you can't use vim. – juanchopanza Aug 24 '13 at 07:53
  • I feel very sorry if my question is a bit silly or n00b, but I'm a quiet new on programming, I feel very pleasant working with vim, so I was thinking that maybe I could use vim in my c++ homeworks. – mao2047 Aug 24 '13 at 07:54
  • @shuuichi_nitori: that is fine. Do not worry. Unfortunately, there are hostile people in here. By the way, do not forget to select an answer when before leaving the thread for the eternity. :) – László Papp Aug 24 '13 at 08:02
  • @shuuichi_nitori I use vim and/or emacs all the time for small to medium sized projects without problems. The question is by no means silly. I have also struggled to find IDE pluggins that reproduce the subset of vim features I am used to, so often I find it more productive to use vim than an IDE. But once a project becomes large, and you require navigation between files, the benefits of the IDE start to show. – juanchopanza Aug 24 '13 at 08:04
  • @juanchopanza yeah, as I said in my question, I will work with little projects, no more than 100 code lines. very good comment. – mao2047 Aug 24 '13 at 08:16

2 Answers2

3

I don't think you need any plugins... the features you want are already there.

-write code (you don't say?)

this is a given

-check and highlight C++ syntax

:syntax enable

-autocompletion (if is possible)

in insert mode, try

ctrl-n
ctrl-p

-compile, run, debugging and return to the editor

vim is an editor, not a complier. You can, however, drop into a shell to run these commands or use :!commandname. Try one of the following

ctrl-z
g++ -o myprogram myprogram.cpp
fg

or

:!g++ -o myprogram myprogram.cpp

or just keep another terminal open.

-tree-view project files on the side

:!tree -C | less -R

-statusbar

already at the bottom. Try gvim for more toolbars et cetra.

Have fun!

BTW - this message was brought to you via vim and pentadactyl

idfah
  • 1,328
  • 10
  • 16
  • I saw somewhere the :make option and c++ code, I don't know if that is even possible, maybe it's just my imagination. – mao2047 Aug 24 '13 at 08:28
  • 1) As for me, syntax is actually enabled by default. 2) !tree -C is probably not what he wanted. If you check nerd tree, it can show the tree while editing the files, just like an IDE. Your solution would require manual intervention all the time to get there. 3) The keyword completion will not work either without proper tagging with ctags for big projects. 4) The default statusbar is also not the same he wished with the powerline. – László Papp Aug 24 '13 at 08:28
  • 1
    `:!make` works if you have a makefile – idfah Aug 24 '13 at 08:29
  • @shuuichi_nitori: you should avoid using Makefiles nowadays. :) – László Papp Aug 24 '13 at 08:29
  • @LaszloPapp 1) ok 2) This works to peek and see. Having the tree there all the time is, in my opinion, a waste of space 3) completion works well for me. You are right though, it is not perfect. – idfah Aug 24 '13 at 08:33
  • 2) you can actually hide the nerdtree tree anytime, and bring it back. The point is merely that nerdtree is better suggestion from IDE point of view to have what IDE does: simultaneous view. 3) Try any bigger project. Your solution will not work without ctags, especially for custom code completion. – László Papp Aug 24 '13 at 08:35
  • @idfah thank you very much for your answer, specally the compile, run and debugging part, it was very useful! – mao2047 Aug 24 '13 at 08:40
2

Some plugins that might help you and I tried in the past when I was trying to get started with vim long ago:

IDE: http://www.vim.org/scripts/script.php?script_id=213

Tree view: http://www.vim.org/scripts/script.php?script_id=1658

Debugging: http://www.vim.org/scripts/script.php?script_id=3039

Completion: http://ctags.sourceforge.net/ and http://www.vim.org/scripts/script.php?script_id=1520

Statusbar: http://www.vim.org/scripts/script.php?script_id=3881 and its successor http://usevim.com/2013/01/23/vim-powerline/

You can search for further plugins at http://www.vim.org/scripts/index.php

That being said, I use vim just fine without any plugin for daily C++ development. It is also handy because I can use the same workflow when ssh'ing onto a server or someone else's machine without the consideration of major differences.

Also C++ syntax highlight works by default as such plugins for languages are usually included into the distributed vim, already.

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • thanks for your answer, I know some other plugins such as NERDTree (for treeview files), c.vim (for c++ thing), bufexplorer, Tagbar, but I don't know which one for debugging and run the program right from the same terminal. also, I want to know how to put them all together and make it owrk fine. – mao2047 Aug 24 '13 at 07:39
  • 1
    Have you checked the debugger plugin? What do you mean by put together? You simply download the plugins and that is all, or you use vim like me. I wrote both ways? Does this answer your question? – László Papp Aug 24 '13 at 07:40
  • I do not know know who downvoted this reply without further comment as suggested, but it seems a bit rude to me. It is likely "VioletGiraffe" who also made unproductive notes to "shuuichi_nitori". – László Papp Aug 24 '13 at 07:40
  • ok, Iby status bar I was talking about Powerline – mao2047 Aug 24 '13 at 08:13