-
Notifications
You must be signed in to change notification settings - Fork 3
/
.vimrc
99 lines (80 loc) · 3.03 KB
/
.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"
" Source: https://code.google.com/p/chromiumembedded/wiki/VimConfiguration
"
" Show line numbers.
" set number
" Turn on syntax highlighting.
syntax on
nmap <F5> :!./cscope.sh<Return> :cs r<Return><Return>
" no EOL whitespace
autocmd FileType c,cc,h,hpp,cpp autocmd BufWritePre <buffer> :%s/\s\+$//e
" Detect if the current file type is a C-like language.
au BufNewFile,BufRead *.h,*.cc,*.cpp call SetupForCLang()
" Highlight lines longer than 80 characters.
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
" Configuration for C-like languages.
function! SetupForCLang()
" Alternately, uncomment these lines to wrap at 80 characters.
" setlocal textwidth=80
" setlocal wrap
" Use 2 spaces for indentation.
setlocal shiftwidth=2
setlocal tabstop=2
setlocal softtabstop=2
setlocal expandtab
" Configure auto-indentation formatting.
setlocal cindent
setlocal cinoptions=h1,l1,g1,t0,i4,+4,(0,w1,W4
setlocal indentexpr=GoogleCppIndent()
let b:undo_indent = "setl sw< ts< sts< et< tw< wrap< cin< cino< inde<"
" Uncomment these lines to map F5 to the CEF style checker. Change the path to match your system.
" map! <F5> <Esc>:!python ~/code/chromium/src/cef/tools/check_style.py %:p 2> lint.out<CR>:cfile lint.out<CR>:silent !rm lint.out<CR>:redraw!<CR>:cc<CR>
" map <F5> <Esc>:!python ~/code/chromium/src/cef/tools/check_style.py %:p 2> lint.out<CR>:cfile lint.out<CR>:silent !rm lint.out<CR>:redraw!<CR>:cc<CR>
endfunction
" From https://github.com/vim-scripts/google.vim/blob/master/indent/google.vim
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
" TODO: I don't know to correct it:
" namespace test {
" void
" ....<-- invalid cindent pos
"
" void test() {
" }
"
" void
" <-- cindent pos
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 =~ '^.\{-}\(/\*.\{-}\)\@<!\*/'
let l:in_comment = 1
elseif l:in_comment == 1
if l:pline =~ '/\*\(.\{-}\*/\)\@!'
let l:in_comment = 0
endif
elseif l:pline_indent == 0
if l:pline !~# '\(#define\)\|\(^\s*//\)\|\(^\s*{\)'
if l:pline =~# '^\s*namespace.*'
return 0
else
return l:orig_indent
endif
elseif l:pline =~# '\\$'
return l:orig_indent
endif
else
return l:orig_indent
endif
let l:pline_num = prevnonblank(l:pline_num - 1)
endwhile
return l:orig_indent
endfunction