Hello
In VIM i want to map say function key Fn for compiling the currently open C/C++ file. Is that possible ? If yes please guide me.
Hello
In VIM i want to map say function key Fn for compiling the currently open C/C++ file. Is that possible ? If yes please guide me.
yes it is possible. Do you have a Makefile? Then insert this into your vimrc:
nnoremap <f1> :make<return>
This remaps the F1 key to invoke the internal command “make” of vim, which if you're running on a Linux machine will call gnu Make.
For more help, run :help :make
and :help :nnoremap
It is certainly possible and is my preferred way of working.
I have the following in my .vimrc
:
nnoremap <F5> :make<CR>
This will call 'makeprg'
, which defaults to 'make'
. Then you can use the results in Vim's Quickfix mode to tackle compilations errors, warnings, etcetera, which (with the correct setup) will deliver your cursor right to where the error lies in your code.
If you just want to compile the current file, you could set 'makeprg'
to something other than 'make
', such as your compiler, followed by the current file:
:set makeprg=g++\ %
[but then you'll need to add compiler flags such as include paths, etc.]
Help topics in Vim to get you underway:
Fully subscribing the Johnsyweb's answer, I would also recommend to take a look at SingleCompile plugin. If it's sufficient for you to quickly compile single-file program, this plugin could just suit your needs.