Skip to content

Instantly share code, notes, and snippets.

@tlvince
Created October 21, 2011 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlvince/1303553 to your computer and use it in GitHub Desktop.
Save tlvince/1303553 to your computer and use it in GitHub Desktop.
Vim Build and Run
" 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
@tlvince
Copy link
Author

tlvince commented Oct 21, 2011

Add this in vimrc and press <commar> + m to call make 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 as src), but is quick and simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment