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.
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.]
If you're using an alternative build system, such as Boost Build, SCons, et cetera, then I humbly recommend using Makeshift
to set 'makeprg'
for you.
Help topics in Vim to get you underway:
:help :make
:help :nnoremap
:help :set
:help 'makeprg'
:help :_%
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With