-
Notifications
You must be signed in to change notification settings - Fork 0
Vim Functionality
Piping edited this page Oct 13, 2018
·
1 revision
- install proper language server in your machine
- use
vim-plug
to help installing plugin with easy -
vimrc
setup code
Plug 'natebosch/vim-lsc'
let g:lsc_server_commands = {
\ 'c': 'cquery --init="{\"cacheDirectory\": \"/tmp/cquery_cache\"}"',
\ 'cpp': 'cquery --init="{\"cacheDirectory\": \"/tmp/cquery_cache\"}"',
\ 'python' : 'pyls',
\ }
if has( 'python' ) || has( 'python3' )
Plug 'maralla/completor.vim'
let g:completor_refresh_always = 0 "avoid flickering
let g:completor_complete_options = 'menuone,noselect'
let g:completor_javascript_omni_trigger = "\\w+$|[\\w\\)\\]\\}\'\"]+\\.\\w*$"
let g:completor_python_omni_trigger = ".*"
""" for c/cpp, using either trigger or built-in support
" let g:completor_cpp_omni_trigger = '(\\.|->|#|::)\\s*(\\w*)$'
let g:completor_clang_binary = '/usr/local/bin/cquery-clang'
nmap <tab> <Plug>CompletorCppJumpToPlaceholder
else " use vim-lsc's complete functionality
set completeopt-=preview
endif
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <C-Y> pumvisible() ? "\<C-y>" : '\<C-R>"'
""""""""""""""""""""""""""""""
nnoremap <silent> <leader>gh :LSClientShowHover<cr>
nnoremap <silent> <leader>gd :LSClientGoToDefinition<cr>
nnoremap <silent> <leader>gr :LSClientFindReferences<cr>
nnoremap <silent> <leader>gs :LSClientDocumentSymbol<cr>
nnoremap <silent> <leader>gn :LSClientRename<cr>
nnoremap <silent> <leader>gxx :LSClientFindCodeActions<cr>
nnoremap <silent> <leader>gxi :LSClientFindImplementations<cr>
nnoremap <silent> <leader>gxs :LSClientWorkspaceSymbol<cr>
"""""""""""""""""""""""""""""""""""""""""
"" Code/Text AutoFormat,AutoComplete
"""""""""""""""""""""""""""""""""""""""""
function! SetupCodeEnvironment()
"set trigger for language-client's omnifunc
setlocal formatprg=
setlocal formatexpr=
setlocal omnifunc=lsc#complete#complete
if &filetype == 'c' || &filetype == 'cpp'
if executable('cquery-clang-format')
if empty(glob('~/.clang-format'))
setlocal formatprg=cquery-clang-format\ --style='Webkit'
setlocal equalprg=cquery-clang-format\ --style='Webkit'
else
setlocal formatprg=cquery-clang-format\ --style='file'
setlocal equalprg=cquery-clang-format\ --style='file'
endif
endif
elseif &ft == 'javascript'
if executable('js-beautify')
" setlocal equalprg='js-beautify '
endif
elseif &ft == 'python'
setlocal makeprg=python\ %
else
setlocal formatprg=
setlocal formatexpr=
setlocal formatexpr=
setlocal omnifunc=
endif
endfunction