diff options
author | gxlin <[email protected]> | 2021-06-07 19:54:10 +0800 |
---|---|---|
committer | gxlin <[email protected]> | 2021-06-07 22:18:37 +0800 |
commit | 77af1ea1165d678a0b3953c43eaf7ddfc262ef68 (patch) | |
tree | a06c4dc22d5498e8668a859be8a340493f01b184 | |
parent | bd7d13c48383551cb4b81f9a62e3f38431b168c2 (diff) | |
download | dotfiles-77af1ea1165d678a0b3953c43eaf7ddfc262ef68.tar.gz dotfiles-77af1ea1165d678a0b3953c43eaf7ddfc262ef68.tar.bz2 dotfiles-77af1ea1165d678a0b3953c43eaf7ddfc262ef68.zip |
Add lsp config for vim
-rw-r--r-- | .emacs.d/init.el | 1 | ||||
-rw-r--r-- | .emacs.d/modes/init-lsp-mode.el | 13 | ||||
-rw-r--r-- | .vim/init.vim | 1 | ||||
-rw-r--r-- | .vim/keybindings.vim | 45 | ||||
-rw-r--r-- | .vim/plugins/leaderf.vim | 2 | ||||
-rw-r--r-- | .vim/plugins/lsp.vim | 39 | ||||
-rw-r--r-- | .vim/plugins/misc.vim | 2 | ||||
-rw-r--r-- | .vim/plugins/vista.vim | 9 |
8 files changed, 109 insertions, 3 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 1d345b6..7d213be 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -36,6 +36,7 @@ (require 'init-evil-mode) (require 'init-org-mode) +(require 'init-lsp-mode) ;; ledger-mode (use-package ledger-mode diff --git a/.emacs.d/modes/init-lsp-mode.el b/.emacs.d/modes/init-lsp-mode.el new file mode 100644 index 0000000..b5c391a --- /dev/null +++ b/.emacs.d/modes/init-lsp-mode.el @@ -0,0 +1,13 @@ +(use-package lsp-mode + :ensure t + :hook + ((go-mode . lsp-deferred) + (lsp-mode . lsp-enable-which-key-integration)) + :commands (lsp lsp-deferred) + :config + (evil-define-key 'normal lsp-mode-map + (kbd "gd") 'lsp-find-definition + (kbd "gr") 'lsp-find-references) + (add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]\\.git\\'") + +(provide 'init-lsp-mode) diff --git a/.vim/init.vim b/.vim/init.vim index 31ce971..7f2fbdc 100644 --- a/.vim/init.vim +++ b/.vim/init.vim @@ -105,6 +105,7 @@ nnoremap ]ww :wincmd j <CR> nnoremap <leader>cd :cd %:p:h<CR> :pwd<CR> source ~/.dotfiles/.vim/plugins/init.vim +source ~/.dotfiles/.vim/keybindings.vim silent colorscheme onehalfdark diff --git a/.vim/keybindings.vim b/.vim/keybindings.vim new file mode 100644 index 0000000..7a68992 --- /dev/null +++ b/.vim/keybindings.vim @@ -0,0 +1,45 @@ +imap <C-b> <Left> +imap <C-f> <Right> +imap <C-n> <Down> +imap <C-p> <Up> +imap <C-a> <C-o>:call <SID>home()<CR> +imap <C-e> <End> +imap <C-d> <Del> +imap <C-h> <BS> +imap <C-k> <C-r>=<SID>kill_line()<CR> + +cmap <C-p> <Up> +cmap <C-n> <Down> +cmap <C-b> <Left> +cmap <C-f> <Right> +cmap <C-a> <Home> +cmap <C-e> <End> +cnoremap <C-d> <Del> +cnoremap <C-h> <BS> +cnoremap <C-k> <C-f>D<C-c><C-c>:<Up> + +function! s:home() + let start_col = col('.') + normal! ^ + if col('.') == start_col + normal! 0 + endif + return '' +endfunction + +function! s:kill_line() + let [text_before_cursor, text_after_cursor] = s:split_line_text_at_cursor() + if len(text_after_cursor) == 0 + normal! J + else + call setline(line('.'), text_before_cursor) + endif + return '' +endfunction + +function! s:split_line_text_at_cursor() + let line_text = getline(line('.')) + let text_after_cursor = line_text[col('.')-1 :] + let text_before_cursor = (col('.') > 1) ? line_text[: col('.')-2] : '' + return [text_before_cursor, text_after_cursor] +endfunction diff --git a/.vim/plugins/leaderf.vim b/.vim/plugins/leaderf.vim index 584322a..116a994 100644 --- a/.vim/plugins/leaderf.vim +++ b/.vim/plugins/leaderf.vim @@ -19,4 +19,4 @@ xnoremap gf :<C-U><C-R>=printf("Leaderf! rg -F -e %s ", leaderf#Rg#visual())<CR> noremap go :<C-U>Leaderf! rg --recall<CR> let g:Lf_WorkingDirectoryMode = 'AF' -let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git', '.hg'] +let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git', '.hg', '.projectile'] diff --git a/.vim/plugins/lsp.vim b/.vim/plugins/lsp.vim new file mode 100644 index 0000000..1a5704b --- /dev/null +++ b/.vim/plugins/lsp.vim @@ -0,0 +1,39 @@ +Plug 'prabirshrestha/vim-lsp' + +if executable('gopls') + au User lsp_setup call lsp#register_server({ + \ 'name': 'gopls', + \ 'cmd': {server_info->['gopls']}, + \ 'allowlist': ['go'], + \ }) +endif + +function! s:on_lsp_buffer_enabled() abort + setlocal omnifunc=lsp#complete + setlocal signcolumn=no + if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif + nmap <buffer> gd <plug>(lsp-definition) + nmap <buffer> gs <plug>(lsp-document-symbol-search) + nmap <buffer> gS <plug>(lsp-workspace-symbol-search) + nmap <buffer> gr <plug>(lsp-references) + nmap <buffer> gi <plug>(lsp-implementation) + nmap <buffer> gt <plug>(lsp-type-definition) + nmap <buffer> <leader>rn <plug>(lsp-rename) + nmap <buffer> [g <plug>(lsp-previous-diagnostic) + nmap <buffer> ]g <plug>(lsp-next-diagnostic) + nmap <buffer> K <plug>(lsp-hover) + inoremap <buffer> <expr><c-f> lsp#scroll(+4) + inoremap <buffer> <expr><c-d> lsp#scroll(-4) + + let g:lsp_format_sync_timeout = 1000 + autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync') + + " refer to doc to add more commands +endfunction + +augroup lsp_install + au! + " call s:on_lsp_buffer_enabled only for languages that has the server registered. + autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() +augroup END + diff --git a/.vim/plugins/misc.vim b/.vim/plugins/misc.vim index 5067f5a..f79b438 100644 --- a/.vim/plugins/misc.vim +++ b/.vim/plugins/misc.vim @@ -1,7 +1,5 @@ Plug 'scrooloose/nerdtree', {'on': 'NERDTreeToggle'} -map <C-n> :NERDTreeToggle<CR> - Plug 'skywind3000/asyncrun.vim' let g:asyncrun_open = 6 " the number of lines of quickfix window diff --git a/.vim/plugins/vista.vim b/.vim/plugins/vista.vim new file mode 100644 index 0000000..02264b9 --- /dev/null +++ b/.vim/plugins/vista.vim @@ -0,0 +1,9 @@ +Plug 'liuchengxu/vista.vim' + +let g:vista_default_executive = 'ctags' + +let g:vista_executive_for = { + \ 'go': 'vim_lsp', + \ } + +nnoremap <leader>s :Vista<CR> |