]> git.rmz.io Git - dotfiles.git/blob - vim/ftplugin/cpp.vim
qutebrowser: update bookmarks
[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 "TODO these are ignored because we set indentexpr in `indent/cpp.vim`
10 " Ideally, indentexpr should read the settings from .clang-format if it exists
11 setlocal nosmartindent
12 setlocal autoindent
13 setlocal cinkeys-=0# " don't reindent PP directives
14 setlocal cinoptions+=:0 " don't indent case labels
15
16 " Load the doxygen syntax
17 let b:load_doxygen_syntax = 1
18
19 augroup fswitch_cpp
20 au!
21 au BufEnter *.h let b:fswitchdst = 'c,cpp'
22 au BufEnter *.h let b:fswitchlocs = '.,reg:|include.*|src|'
23 au BufEnter *.hpp let b:fswitchdst = 'cpp,c'
24 au BufEnter *.hpp let b:fswitchlocs = '.,reg:|include.*|src|'
25 au BufEnter *.cpp let b:fswitchdst = 'hpp,h'
26 au BufEnter *.cpp let b:fswitchlocs = '.,reg:|src|include/**|'
27 augroup END
28
29 let g:switch_custom_definitions =
30 \ [
31 \ ['EXPECT_FALSE', 'EXPECT_TRUE'],
32 \ ['EXPECT_EQ', 'EXPECT_NE'],
33 \ ['EXPECT_LT', 'EXPECT_GT'],
34 \ ['ASSERT_FALSE', 'ASSERT_TRUE'],
35 \ ['ASSERT_EQ', 'ASSERT_NE'],
36 \ ['ASSERT_LT', 'ASSERT_GT']
37 \ ]
38
39 let g:switch_const_definitions =
40 \ [ {
41 \ '\%(const \)\@!\([[:alnum:]_:<>]\{-}\) \%(&\)\@!': 'const \1 ',
42 \ 'const \([[:alnum:]_:<>]\{-}\) &\@!': 'const \1 &' ,
43 \ 'const \([[:alnum:]_:<>]\{-}\) &': '\1 '
44 \ } ]
45
46 nnoremap <buffer> <leader>c :call switch#Switch({'definitions': g:switch_const_definitions})<cr>
47
48 nnoremap <buffer> gd :YcmCompleter GoTo<CR>
49 nnoremap <buffer> <C-W>d :vs<CR>:YcmCompleter GoTo<CR>
50 nnoremap <buffer> gD :YcmCompleter GoToReferences<CR>
51
52 " format with =
53 call operator#user#define_ex_command('ycmcompleter-format', 'YcmCompleter Format')
54 map <buffer> = <Plug>(operator-ycmcompleter-format)
55 vnoremap <buffer> = :YcmCompleter Format<CR>
56 " restore = mapping to g=
57 nnoremap <buffer>g= =
58 vnoremap <buffer>g= =
59
60 setlocal errorformat=
61 setlocal errorformat+=%f:%l:%c:\ %trror:\ %m
62 setlocal errorformat+=%f:%l:%c:\ %tarning:\ %m
63 setlocal errorformat+=%D%*\\a[%*\\d]:\ Entering\ directory\ [`']%f'
64 setlocal errorformat+=%X%*\\a[%*\\d]:\ Leaving\ directory\ [`']%f'
65 setlocal errorformat+=%D%*\\a:\ Entering\ directory\ [`']%f'
66 setlocal errorformat+=%X%*\\a:\ Leaving\ directory\ [`']%f'
67 setlocal errorformat+=%*[^[]\[%tRROR\]%m\ \[%f:%l\]
68 setlocal errorformat+=%*[^[]\[%tARNING\]%m\ \[%f:%l\]
69
70 packadd termdebug
71 let g:termdebug_wide = 1
72 function! s:Debug(...)
73 tabedit %
74 let t:debug_tab=1
75 au BufDelete !gdb ++once if exists('t:debug_tab') | tabclose | endif
76
77 "TODO restore mappings
78 "TODO make mappings local to source buffer
79 nnoremap <buffer> <C-T> :call TermDebugSendCommand('advance -source '.expand('%').' -line '.line("."))<CR>
80 nnoremap <buffer> <C-S> :Step<CR>
81 nnoremap <buffer> <C-N> :Over<CR>
82 nnoremap <buffer> <C-F> :Finish<CR>
83 endfunction
84 command! -nargs=* -complete=file -bang Debug call <SID>Debug() | Termdebug<bang> <args>
85 command! -nargs=+ -complete=file -bang DebugCommand call <SID>Debug() | TermdebugCommand<bang> <args>
86
87 setlocal foldmethod=syntax
88 " set foldlevel according to number of matches of 'namespace' and 'class' not
89 " containing ';'
90 function! InitialFoldLevel()
91 let v:errmsg = ""
92 keepjumps keeppatterns silent! 1,/}/s/^\(namespace\|class\) \+[^;]*$//n
93 if v:errmsg == ""
94 let &l:foldlevel=str2nr(split(v:statusmsg)[0])
95 endif
96 endf
97 call InitialFoldLevel()