您的位置:首页 > 其它

vim 键映射<F7><F8><F9>

2013-04-28 09:05 330 查看
写单个程序,如果每次都自己输入:set makeprg=gcc\ .......什么的就太麻烦了.所性自己定义快捷键.当然,大程序就用makefile了.这里只是为了方便下:

---------------------------------------------------------------------------------------------------------------------
,<F7>编译 ,<F8>运行 ,<F9>带参运行
举例:写文件foo_001.c 则make成可执行文件001 .如果有参,文件应是:foo_001.in 则输出foo_001.out
分隔符是下划线,稍微看下就可以随自己个性修改使用
----------------------------------------------------------------------------------------------------------------------
nmap <leader><F7> :call Gcc_make()<cr><cr>
nmap <leader><F8> :call Gcc_run()<cr><cr>
nmap <leader><F9> :call Gcc_run_infile()<cr><cr><cr>

function Gcc_run()
exec "! mv %:r `echo %:r | cut -d'_' -f2`"
exec "!./`echo %:r | cut -d'_' -f2`"
endfunction

function Gcc_run_infile()
exec "! mv %:r `echo %:r | cut -d'_' -f2`"
exec "!./`echo %:r | cut -d'_' -f2` < %:r.in > %:r.out"
exec "!cat ./%:r.out"
endfunction

function Gcc_make()
exec "w"
let s:input_file = expand("%") . "\\"
let s:output_file = expand("%:r")
exec "set makeprg=gcc\\\ -g\\\ -Wall\\\ " . s:input_file "-o\\\ " . s:output_file
exec "make"
endfunction
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: