Vim 写 C/C++ 的配置
2018-03-24 14:15
190 查看
准备重装系统,把一些当前使用的 .vimrc
上传一下,后续继续更新
基本的配置,缩进显示行号等给每个 C/C++ 文件添加头部,显示作者,文件创建时间
F5 编译 F6 执行 C/C++源代码
Ctrl + F 利用用 astyle 格式化代码
使用 clang_complete 对代码进行补全
set tabstop=4 set expandtab set softtabstop=4 set shiftwidth=4 set cindent set number syntax on "-- new file .h .c cpp, add file header ---------------------------- autocmd BufNewFile *.[ch],*.cpp exec ":call SetTitle()" func SetTitle() call setline(1,"/*") call append(line("."), " * Created by zxh on ".strftime("%Y/%m/%d")." . All rights reserved.") call append(line(".")+1, " */") call append(line(".")+2, "") endfunc " ------------------------------------------------------------------ " C/C++/Go---------------------- F5 Compile, F6 Execute ------------ func! CompileC() exec "w" let compilecmd="!clang " let compileflag=" " if search("math\.h") != 0 let compileflag .= " -lm " endif exec compilecmd." % ".compileflag endfunc func! CompileCpp() exec "w" let compilecmd="!clang++ " let compileflag="" exec compilecmd." % ".compileflag endfunc func! CompileGolang() exec "w" let compilecmd="!go run " let compileflag=" %< " exec compilecmd." % ".compileflag endfunc func! CompileCode() exec "w" if &filetype == "cpp" exec "call CompileCpp()" elseif &filetype == "c" exec "call CompileC()" elseif &filetype == "go" exec "call CompileGolang()" endif endfunc func! RunResult() exec "w" if &filetype == "cpp" exec "! ./a.out" elseif &filetype == "c" exec "! ./a.out" endif endfunc map <F5> :call CompileCode()<CR> imap <F5> <ESC> :call CompileCode()<CR> vmap <F5> <ESC> :call CompileCode()<CR> map <F6> :call RunResult()<CR> "------------------------------------------------------------------- " use Astyle to format code, <Ctrl + F> ---------------------------- func! CoderFormat() exec "w" if &filetype == "c" || &filetype == "h" exec "!astyle -n --style=kr -s8 %" elseif &filetype == "cpp" exec "!astyle -n --style=google %" endif endfunc map <C-F> :call CoderFormat() <CR> " ------------------------------------------------------------------ " clang_complete --------------------------------------------------- let g:clang_complete_copen=1 let g:clang_use_library =1 " ------------------------------------------------------------------
相关文章推荐
- vim下c++自动补全和类似source insight功能配置
- vim配置C++ IDE
- vim配置文件收集(作为c/c++和脚本开发的环境)
- vim 配置c/c++开发环境
- vim配置C、C++高亮显示
- vim 的C++配置
- vim配置为C/C++开发环境
- 配置vim的c/c++风格
- 推荐参考vim配置文件-c/c++
- vim配置C、C++高亮显示
- 进阶配置你的vim为c++IDE
- Ubuntu下配置C++编辑器VIM
- 在Linux下C/C++编程vim初步配置
- Linux——VIM开发C++自动补全(STL、括号)和开发环境配置
- ubuntu10.10配置vim为C/C++风格
- vim c/c++配置
- [Vim]配置编译运行C/C++程序
- Ubuntu&红帽的vim通用配置(文件头+一键编译执行C/C++/Java单文件)
- 配置vim的C++开发环境
- debian6.0 VIM 编写C++代码配置