Make-compile current buffer
From Vim Tips Wiki
created 2002 · complexity basic · author elian · version 6.0
This tip shows techniques to compile or to run
make for the file in the current buffer. This is useful to list any compile errors in the quickfix window.
 Compile with gcc
If you use
set makeprg=gcc\ -o\ %<\ %
in your vimrc, and your actual file is
:make will compile
file.c with the output
gcc file.c -o file).
If you use GNU
make the above change is not required. Instead, simply use the following command to compile the current file (you need to save it first):
When using other compilers, like Sun
cc, you can adapt the tip to suit your compiler.
 Invoking make
The following allows you to press F7 (in normal mode) to invoke
make to compile the file in the current buffer. If modified, the file is first saved.
" Save and make current file.o function! Make() let curr_dir = expand('%:h') if curr_dir == '' let curr_dir = '.' endif echo curr_dir execute 'lcd ' . curr_dir execute 'make %:r.o' execute 'lcd -' endfunction nnoremap <F7> :update<CR>:call Make()<CR>
- I've done a pretty quick clean up. Would someone please reply here with news about whether it actually works (after testing).
- Need some explanation, including note about (deprecated)
%<. JohnBeckett 04:49, 14 July 2009 (UTC)