Created
October 21, 2011 10:47
-
-
Save tlvince/1303553 to your computer and use it in GitHub Desktop.
Vim Build and Run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Write and build the current file | |
map <leader>m :write<CR> :make %<CR> | |
" Autocommands {{{1 | |
if has('autocmd') | |
" Run the current file if there was no error | |
autocmd QuickFixCmdPost make call BuildAndRun() | |
endif | |
" Run the current file if there was no error after make. | |
function! BuildAndRun() | |
let qflist = getqflist() | |
let run = '! ./%:t:r' | |
if qflist == [] | |
exec run | |
else | |
for error in qflist | |
if error["valid"] | |
return | |
else | |
exec run | |
return | |
endif | |
endfor | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this in
vimrc
and press<commar> + m
to callmake
on the current buffer. If there were no valid errors, run the resulting binary. Doesn't scale well for big projects (e.g. binaries should not be in the same directory assrc
), but is quick and simple.