]> git.rmz.io Git - dotfiles.git/blob - vim/ftplugin/cpp.vim
xkb: Add slash to <AC11>
[dotfiles.git] / vim / ftplugin / cpp.vim
1 setlocal textwidth=100
2
3 " indent 4 spaces
4 setlocal shiftwidth=4
5 setlocal tabstop=4
6 setlocal softtabstop=4
7 setlocal expandtab
8
9 setlocal nosmartindent
10 setlocal autoindent
11 setlocal cinkeys-=0# " don't reindent PP directives
12 setlocal cinoptions+=:0 " don't indent case labels
13
14 " Load the doxygen syntax
15 let b:load_doxygen_syntax = 1
16
17 augroup fswitch_cpp
18 au!
19 au BufEnter *.h let b:fswitchdst = 'c,cpp'
20 au BufEnter *.h let b:fswitchlocs = '.,reg:|include.*|src|'
21 au BufEnter *.hpp let b:fswitchdst = 'cpp,c'
22 au BufEnter *.hpp let b:fswitchlocs = '.,reg:|include.*|src|'
23 au BufEnter *.cpp let b:fswitchdst = 'hpp,h'
24 au BufEnter *.cpp let b:fswitchlocs = '.,reg:|src|include/**|'
25 augroup END
26
27 let g:switch_custom_definitions =
28 \ [
29 \ ['EXPECT_FALSE', 'EXPECT_TRUE'],
30 \ ['EXPECT_EQ', 'EXPECT_NE'],
31 \ ['EXPECT_LT', 'EXPECT_GT'],
32 \ ['ASSERT_FALSE', 'ASSERT_TRUE'],
33 \ ['ASSERT_EQ', 'ASSERT_NE'],
34 \ ['ASSERT_LT', 'ASSERT_GT']
35 \ ]
36
37 let g:switch_const_definitions =
38 \ [ {
39 \ '\%(const \)\@!\([[:alnum:]_:<>]\{-}\) \%(&\)\@!': 'const \1 ',
40 \ 'const \([[:alnum:]_:<>]\{-}\) &\@!': 'const \1 &' ,
41 \ 'const \([[:alnum:]_:<>]\{-}\) &': '\1 '
42 \ } ]
43
44 nnoremap <buffer> <leader>c :call switch#Switch(g:switch_const_definitions, {})<cr>
45
46 nnoremap <buffer> gd :YcmCompleter GoTo<CR>
47 nnoremap <buffer> <C-W>d :vs<CR>:YcmCompleter GoTo<CR>
48
49 " format with =
50 map <buffer> = <Plug>(operator-clang-format)
51 vnoremap <buffer> = :ClangFormat<CR>
52 " restore = mapping to g=
53 nnoremap <buffer>g= =
54 vnoremap <buffer>g= =
55
56 setlocal errorformat=
57 setlocal errorformat+=%f:%l:%c:\ %trror:\ %m
58 setlocal errorformat+=%f:%l:%c:\ %tarning:\ %m
59 setlocal errorformat+=%D%*\\a[%*\\d]:\ Entering\ directory\ [`']%f'
60 setlocal errorformat+=%X%*\\a[%*\\d]:\ Leaving\ directory\ [`']%f'
61 setlocal errorformat+=%D%*\\a:\ Entering\ directory\ [`']%f'
62 setlocal errorformat+=%X%*\\a:\ Leaving\ directory\ [`']%f'
63 setlocal errorformat+=%*[^[]\[%tRROR\]%m\ \[%f:%l\]
64 setlocal errorformat+=%*[^[]\[%tARNING\]%m\ \[%f:%l\]
65
66 packadd termdebug
67 let g:termdebug_wide = 1
68 function! s:Debug(...)
69 tabedit %
70 let t:debug_tab=1
71 au BufDelete !gdb ++once if exists('t:debug_tab') | tabclose | endif
72 endfunction
73 command! -nargs=* -complete=file -bang Debug call <SID>Debug() | Termdebug<bang> <args>
74 command! -nargs=+ -complete=file -bang DebugCommand call <SID>Debug() | TermdebugCommand<bang> <args>
75
76 setlocal foldmethod=syntax
77 " set foldlevel according to number of matches of 'namespace' and 'class' not
78 " containing ';'
79 function! InitialFoldLevel()
80 let v:errmsg = ""
81 keepjumps keeppatterns silent! 1,/}/s/^\(namespace\|class\) \+[^;]*$//n
82 if v:errmsg == ""
83 let &foldlevel=str2nr(split(v:statusmsg)[0])
84 endif
85 endf
86 call InitialFoldLevel()