function! My_compile_command() let l:ext = expand("%:e") if (l:ext == "cpp") exec "!g++ ".expand("%") elseif (l:ext == "c") exec "!gcc ".expand("%") endif endfunction nmap <silent> <leader>gg :call My_compile_command()<cr> nmap <silent> <leader>ea :!./a.out<cr>
写一个vim脚本方便在vim中编译所编辑的文件
最新推荐文章于 2025-12-11 09:29:33 发布
本文介绍了一种在Vim编辑器中实现C/C++代码一键编译和运行的方法。通过定义简单的Vim脚本函数,可以根据文件扩展名自动选择使用g++或gcc进行编译,并直接运行生成的a.out文件。
2197

被折叠的 条评论
为什么被折叠?



