Created
February 19, 2016 02:56
-
-
Save jaege/3b2fa10b3e701ee57b8f to your computer and use it in GitHub Desktop.
VIM autocmd to compile and run single source file.
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
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). | |
autocmd! | |
" 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> | |
else | |
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> | |
endif | |
augroup END | |
endif |
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?
It is to get the current file name without its extension, for example:
algorithm.c =>:% <=> algorithm
It is a characteristic of Vim.
more information: http://vimdoc.sourceforge.net/htmldoc/cmdline.html#:_%%3C
Thanks for the info!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?