Skip to content

Instantly share code, notes, and snippets.



Created Feb 19, 2016
What would you like to do?
VIM autocmd to compile and run single source file.
if has("autocmd")
augroup vimrcCompileMap
" Remove ALL autocommands for the current group. This prevents having the
" autocommands defined twice (e.g., after sourcing the .vimrc file again).
" Map <F5> to save, compile and run single source file.
if has("win32")
autocmd FileType cpp nnoremap <buffer> <F5> :w<CR>:!cls && cl /EHsc % && %< <CR>
autocmd FileType python nnoremap <buffer> <F5> :w<CR>:!py % <CR>
autocmd FileType c nnoremap <buffer> <F5> :w<CR>:!gcc -o %< % && ./%< <CR>
autocmd FileType cpp nnoremap <buffer> <F5> :w<CR>:!g++ -o %< % && ./%< <CR>
autocmd FileType python nnoremap <buffer> <F5> :w<CR>:!python % <CR>
augroup END

This comment has been minimized.

Copy link

@ayhon ayhon commented Dec 3, 2019

What does the "%<" mean in the gcc commands in line 12 and 13? I suppose it gets the current filename of the file being editted, but is that a feature of vim or of gcc?

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