From 5241d5e70cfb32049a65c30dbdcdf49a130459d7 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Wed, 4 Jun 2014 05:35:47 +0100 Subject: [PATCH] vim: google c++ indent style for cpp + syntax foldmethod --- vim/ftplugin/cpp.vim | 1 + vim/indent/cpp.vim | 69 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 vim/ftplugin/cpp.vim create mode 100644 vim/indent/cpp.vim diff --git a/vim/ftplugin/cpp.vim b/vim/ftplugin/cpp.vim new file mode 100644 index 0000000..16ffc97 --- /dev/null +++ b/vim/ftplugin/cpp.vim @@ -0,0 +1 @@ +setlocal foldmethod=syntax diff --git a/vim/indent/cpp.vim b/vim/indent/cpp.vim new file mode 100644 index 0000000..5484695 --- /dev/null +++ b/vim/indent/cpp.vim @@ -0,0 +1,69 @@ +" +" VIM C++ Indent file. +" Inspired by Google's C++ Style guide: +" http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml +" + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + + +function! GoogleCppIndent() + let l:cline_num = line('.') + + let l:orig_indent = cindent(l:cline_num) + + if l:orig_indent == 0 | return 0 | endif + + let l:pline_num = prevnonblank(l:cline_num - 1) + let l:pline = getline(l:pline_num) + if l:pline =~# '^\s*template' | return l:pline_indent | endif + + if l:orig_indent != &shiftwidth | return l:orig_indent | endif + + let l:in_comment = 0 + let l:pline_num = prevnonblank(l:cline_num - 1) + while l:pline_num > -1 + let l:pline = getline(l:pline_num) + let l:pline_indent = indent(l:pline_num) + + if l:in_comment == 0 && l:pline =~ '^.\{-}\(/\*.\{-}\)\@