]> git.rmz.io Git - dotfiles.git/blob - vim/ftplugin/cpp.vim
vim: do not Plug UltiSnips in nvim
[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 = 'cpp,cc,c'
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 " Disable ale as we use ycm
49 let b:ale_enabled = 0
50
51 nnoremap <buffer> gd :YcmCompleter GoTo<CR>
52 nnoremap <buffer> <C-W>d :vs<CR>:YcmCompleter GoTo<CR>
53 nnoremap <buffer> gD :YcmCompleter GoToReferences<CR>
54
55 nnoremap <buffer> <leader>fi :YcmCompleter FixIt<CR>
56 nnoremap <buffer> <leader>fr :YcmCompleter RefactorRename<space>
57
58 " format with =
59 call operator#user#define_ex_command('ycmcompleter-format', 'YcmCompleter Format')
60 map <buffer> = <Plug>(operator-ycmcompleter-format)
61 vnoremap <buffer> = :YcmCompleter Format<CR>
62 " restore = mapping to g=
63 nnoremap <buffer>g= =
64 vnoremap <buffer>g= =
65
66 " hover popup
67 let g:ycm_auto_hover = ''
68 let b:ycm_hover = { 'command': 'GetDoc', 'syntax': &filetype }
69 nmap <buffer> gh <plug>(YCMHover)
70 nmap <buffer> gH :YcmCompleter GetDoc<CR>
71
72 setlocal errorformat=
73 " TODO I don't remember these errorformat or what they match, maybe CMake? {{{
74 setlocal errorformat+=\ %##%n\ %m\ %f:%l:%c
75 setlocal errorformat+=\ %##%n\ %m\ %f
76 setlocal errorformat+=%n
77 "}}}
78 setlocal errorformat+=%f:%l:%c:\ %trror:\ %m
79 setlocal errorformat+=%f:%l:%c:\ %tarning:\ %m
80 setlocal errorformat+=%D%*\\a[%*\\d]:\ Entering\ directory\ [`']%f'
81 setlocal errorformat+=%X%*\\a[%*\\d]:\ Leaving\ directory\ [`']%f'
82 setlocal errorformat+=%D%*\\a:\ Entering\ directory\ [`']%f'
83 setlocal errorformat+=%X%*\\a:\ Leaving\ directory\ [`']%f'
84 setlocal errorformat+=%*[^[]\[%tRROR\]%m\ \[%f:%l\]
85 setlocal errorformat+=%*[^[]\[%tARNING\]%m\ \[%f:%l\]
86
87 packadd termdebug
88 let g:termdebug_wide = 1
89 function! s:Debug(...)
90 tabedit %
91 let t:debug_tab=1
92 au BufDelete !gdb ++once if exists('t:debug_tab') | tabclose | endif
93
94 "TODO restore mappings
95 "TODO make mappings local to source buffer
96 nnoremap <buffer> <C-T> :call TermDebugSendCommand('advance -source '.expand('%').' -line '.line("."))<CR>
97 nnoremap <buffer> <C-S> :Step<CR>
98 nnoremap <buffer> <C-N> :Over<CR>
99 nnoremap <buffer> <C-F> :Finish<CR>
100 endfunction
101 command! -nargs=* -complete=file -bang Debug call <SID>Debug() | Termdebug<bang> <args>
102 command! -nargs=+ -complete=file -bang DebugCommand call <SID>Debug() | TermdebugCommand<bang> <args>
103
104 setlocal foldmethod=syntax
105 " set foldlevel according to number of matches of 'namespace' and 'class' not
106 " containing ';'
107 function! InitialFoldLevel()
108 let v:errmsg = ""
109 keepjumps keeppatterns silent! 1,/}/s/^\(namespace\|class\) \+[^;]*$//n
110 if v:errmsg == ""
111 let &l:foldlevel=str2nr(split(v:statusmsg)[0])
112 endif
113 endf
114 call InitialFoldLevel()