.vimrc 2018/08/08 更新

  • 基本的配置,缩进显示行号等
  • 给每个 C/C++ 文件添加头部,显示作者,文件创建时间
  • F5 编译执行 C/C++源代码
  • Ctrl + F 利用用 astyle 格式化代码
  • 使用 clang_complete 对代码进行补全

注: clang_complete 需要vim支持python,可以使用vim –version查看是否有+python(3)的选项,没有的话重装vim


set number
syntax on " -- New file .h .c .cpp, add file header --
autocmd BufNeWFile *.[ch],*.cpp exec ":call CFileHeader()"
func CFileHeader()
call setline(1, "// File: ".strftime(expand('%d')))
call append(line("."), "// Author: xianhui (definezxh@163.com)")
call append(line(".")+1, "// Date: " .strftime("%Y/%m/%d %H:%M:%S"))
call append(line(".")+2, "")
exec "$"
endfunc " -- .c .cpp .h file indent --
autocmd BufEnter *.[ch],*.cpp exec ":call CFileIndent()"
func CFileIndent()
set cindent
set tabstop=4
set softtabstop=4
set expandtab
set shiftwidth=4
endfunc " -- Use Astyle to format code, <Ctrl + F> --
func CodeFormat()
exec "w"
if &filetype == "h"
exec "!astyle -n --style=kr -s4 %"
elseif &filetype == "c"
exec "!astyle -n --style=kr -s4 %"
elseif &filetype == "cpp"
exec "!astyle -n --style=google %"
endif
endfunc
map <C-F> :call CodeFormat() <CR> " -- F5 compile and run code --
func CompileC()
exec "w"
let compilecmd = "!clang "
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 CompileRun()
exec "w"
if &filetype == "c"
exec "call CompileC()"
elseif &filetype == "cpp"
exec "call CompileCpp()"
endif
exec "! ./a.out"
endfunc
map<F5> <ESC> :call CompileRun() <CR> " use clang_complete complete code
let g:clang_library_path = '/usr/lib/llvm-3.8/lib'
"let g:clang_library_path = 'usr/lib64/libclang.so.3.8'

Vim 写 C/C++ 的配置的更多相关文章

  1. 就是要用Vim写Vue

    Vim关于Vue的生态链还是很少,不过凑活凑活还是能用的. 缩进 缩进采用的是两个空格,.vimrc配置: au BufNewFile,BufRead *.html,*.js,*.vue set ta ...

  2. vim 常用插件功能跟配置

    在之前的公司,一直是使用别人配置好的vim 环境,他当时配置的功能很强大,查看源码的时候,非常的方便.至少我一直都是用它来看源码,从来没有使用过source insight.现在换了工作,但之前养成的 ...

  3. Vim 写 iOS App

    Vim 写 iOS App 我们都知道 Vim 和 Emacs 都是文本编辑器中的上古神器,你也许用 ctags,cscopes 配合 Vim 完成过大型 C 或者 C++ 的开发,你也许配合过其他插 ...

  4. 使用Vim写LaTeX代码(Vim+Vimtex+Skim)

    最近在写博客的时候发现对数学公式的支持并不好,于是就想寻找一个解决方案.我本身是一个爱折腾的人,有时尽管有现成的解决方案我有事也不愿意去用.于是多方查找资料,想寻求一个自定义的解决方案,最终把自己的目 ...

  5. vim学习、各类插件配置与安装

    vim学习.各类插件配置与安装 vim 插件 配置 1. vim学习 vim基础学习:根据网上流行基础文章<简明Vim练级攻略>,进阶书籍<vim实用技巧>.注:进阶书籍可以在 ...

  6. feign三:覆写feign的默认配置及feign的日志

    feign三:覆写feign的默认配置及feign的日志 默认配置复写 本项目地址:http://192.168.1.103:7601 本例是通过feign调用 eureka项目中的/eureka/a ...

  7. 转载 - Vim 的 Python 编辑器详细配置过程 (Based on Ubuntu 12.04 LTS)

    出处:http://www.cnblogs.com/ifantastic/p/3185665.html Vim 的 Python 编辑器详细配置过程 (Based on Ubuntu 12.04 LT ...

  8. linux常用终端指令+如何用vim写一个c程序并运行

    在装好ubuntu之后今天学习了一些linux的一些基础知识: windows里面打开命令窗口是win+r,在linux系统里面,ctrl+alt+t打开终端,今天的一些指令都是围绕终端来说的 首先s ...

  9. linux下用vim写Python自动缩进的配置

    #首先用 find / -name vimrc 找到vimrc文件#一般在 /etc/vimrc#进入vimrc后加入以下命令 set number set autoindent set shiftw ...

随机推荐

  1. Objective-C NSFileManager 文件管理总结

    createFileAtPath //创建文件 NSFileManager *fm = [NSFileManager defaultManager]; NSString *strpath = [NSS ...

  2. Linux下的ssh实验环境搭建与管理

    实验环境[size=10.5000pt]1:网桥模式[size=10.5000pt]2:安装好vmtoos[size=10.5000pt]3:安装好yum[size=10.5000pt]4:安装好ss ...

  3. string转date

    /*util-->sql*/ java.util.Date utdt; java.sql.Date sqldt =null; SimpleDateFormat simFormat = new S ...

  4. bzoj2780

    AC自动机+树链剖分+线段树/树状数组+dfs序+树链的并 题意:给出n个母串和q个询问串,对于每个询问串输出有多少个母串包含这个询问串 N=∑|母串|<=10^5 Q=∑|询问串|<=3 ...

  5. hebernate基础学习2---属性

    ---------------------------------------------------------------------------------------------------- ...

  6. php phppowerpoint

    今天早上从订阅的 Zend DevZone 看到篇很有意思的文章. Creating PowerPoint 2007 files using PHP. 试了一下. 果然很又意思, 分享给大家吧. 程序 ...

  7. js返回上一层

    Javascript 返回上一页 1. Javascript 返回上一页 history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). wind ...

  8. Python基础数据类型(四) tuple元祖

    元祖tuple(,) 元祖就是不可变的列表 元祖用()表示,元素与元素之间用逗号隔开,数据类型没有限制 tu = ('科比','詹姆斯','乔丹') tu = tuple('123') 小括号中 有一 ...

  9. 如何获得Windows聚焦壁纸0726

    Windows聚焦壁纸缓存位置,绿色部分是你的用户名: (1)找到之后,一般是大于100K的 (2)将图片复制到另一个文件夹img,要用到路径 (3)在改文件夹下新建一个txt; txt文档里写:re ...

  10. 51nod 1222 莫比乌斯反演

    思路: yhx找的反演题 题解已经烂大街了 #pragma GCC optimize("O3") //By SiriusRen #include <bits/stdc++.h ...