Vim and C++
I have a question about vim: how can i configure it for C++ writing ? I mean i would like to write the C++ code and then test it without getting out of vim. Thx.
|
Afaik vi(m) does colour the texts if you open a .cpp file. There's AFAIK no integrated compiler in vi(m).
To open a cpp file using vi type: vi XXX.cpp |
A little vim voodoo:
File number one, call it: compile.vim Code:
" MAPS: ,; will compile your code, ,,; will execute your code. The above file needs to be loaded in oder for it to work, place the following line in your .vimrc: so /path/to/compile.vim You might want to play with the following line (the execute line): au bufenter *.cc,*.cpp,*.c++ nm ,,; :!./a.out<cr> The above line will just execute the code, if it needs input oyu are able to give it and at the end you need to press return/enter to go back to your vi session. You can also redirect it to a file, in this example it is redirected to out note: if any input is required by your code, you need to give it 'blind': au bufenter *.cc,*.cpp,*.c++ nm ,,; :!./a.out > out<cr>:e out<cr> You might have noticed that this will not only compile/execute C++ (*.cpp,*.c++,*.cc) files, but C (*.c)files as well. Hope this is what you wanted. edit PS: Hate those smileys....... Everywhere there's a smiley in the code it should say: : p (without the space in between). |
If you want to know the standard vim commands for compiling and running your code you can also use the following:
To compile your code with make, use: :make This works best if you have a Makefile, but if you just have a single .cpp file and no non-standard libraries you need to add to the command line, you can also do the following to compile a file called foo.cpp. :make foo (Note, no .cpp) If there are compile errors it will bring you to the first error. You can then use the following to navigate the errors: Next error :cn Previous error :cp List errors :cl View the compile log :cope To execute a program, just use something like: :!./foo |
Ok thank u guys for the answer. Im just a beginner in C++ and would like to learn it. The first contact with C i had in Turbo C so i just wanted a similar program. Thx again.
|
All times are GMT -5. The time now is 03:48 PM. |