Last active
February 26, 2019 05:56
-
-
Save adam900710/5c8b371ca68b8ed1104f75ea7d79c8f6 to your computer and use it in GitHub Desktop.
Vimrc for clangd + vim-lsp + keymapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim-lsp + key mapping | |
if executable('clangd') | |
au User lsp_setup call lsp#register_server({ | |
\ 'name': 'clangd', | |
\ 'cmd': {server_info->['clangd', '-compile-commands-dir=/home/adam/compile_commands.d/']}, | |
\ 'whitelist': ['c', 'cpp', 'objc', 'objcpp'], | |
\ }) | |
endif | |
function! s:ShouldComplete() | |
if (getline('.') =~ '#\s*\(include\|import\)') | |
return 0 | |
else | |
if col('.') == 1 | |
return 1 | |
endif | |
for l:id in synstack(line('.'), col('.') - 1) | |
if match(synIDattr(l:id, 'name'), '\CComment\|String\|Number') | |
\ != -1 | |
return 0 | |
endif | |
endfor | |
return 1 | |
endif | |
endfunction | |
function! s:LaunchCompletion() | |
let l:result = "" | |
if s:ShouldComplete() | |
let l:result = "\<C-X>\<C-U>" | |
endif | |
return l:result | |
endfunction | |
function! s:CompleteDot() | |
return '.' . s:LaunchCompletion() | |
endfunction | |
function! s:CompleteArrow() | |
if getline('.')[col('.') - 2] != '-' | |
return '>' | |
endif | |
return '>' . s:LaunchCompletion() | |
endfunction | |
function! s:CompleteColon() | |
if getline('.')[col('.') - 2] != ':' | |
return ':' | |
endif | |
return ':' . s:LaunchCompletion() | |
endfunction | |
autocmd FileType c,h inoremap <expr> <buffer> <C-X><C-U> <SID>LaunchCompletion() | |
autocmd FileType c,h inoremap <expr> <buffer> . <SID>CompleteDot() | |
autocmd Filetype c,h inoremap <expr> <buffer> > <SID>CompleteArrow() | |
autocmd Filetype c,h nnoremap <buffer> <silent> <c-]> :LspDefinition<cr> | |
autocmd FileType c,h set omnifunc=lsp#complete | |
autocmd FileType c,h set completefunc=lsp#complete | |
" vim: set ts=2 sts=2 sw=2 expandtab : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment