From 6c5f19bf6524fc38c4288858f9f03c0fbc325556 Mon Sep 17 00:00:00 2001 From: Oxbian Date: Sat, 2 Dec 2023 22:03:41 +0100 Subject: ADD: CoC Lsp, and update README --- vim/keymaps.vim | 74 +++++++++++++++++++++++++++++++++------------------------ vim/options.vim | 4 +++- vim/plugins.vim | 28 +++++++++------------- 3 files changed, 57 insertions(+), 49 deletions(-) (limited to 'vim') diff --git a/vim/keymaps.vim b/vim/keymaps.vim index 9570949..e568816 100644 --- a/vim/keymaps.vim +++ b/vim/keymaps.vim @@ -7,6 +7,9 @@ let g:maplocalleader = ',' nnoremap :WhichKey '' nnoremap :WhichKey ',' +" Treat long paragraph as a line +map j gj +map k gk """""""""""""""""""" " Window movement @@ -146,34 +149,43 @@ noremap s? z= """"""""""""""""""" " LSP """"""""""""""""""" - -inoremap pumvisible() ? "\" : "\" -inoremap pumvisible() ? "\" : "\" - -" Go to definition -nnoremap ld :LspDefinition - -" Go next diagnostic -nnoremap lnd :LspNextDiagnostic - -" Go previous diagnostic -nnoremap lpd :LspPreviousDiagnostic - -" Go to reference -nnoremap lf :LspReferences - -" Rename object -nnoremap lr :LspRename - -" LSP stop server -nnoremap ls :LspStopServer - -" peek definition of object -nnoremap lp :LspPeekDefinition - -" Code Action -nnoremap la :LspCodeAction - -" Hover information -nnoremap lh :LspHover - +inoremap + \ coc#pum#visible() ? coc#pum#next(1) : + \ CheckBackspace() ? "\" : + \ coc#refresh() +inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" + +" Make to accept selected completion item or notify coc.nvim to format +" u breaks current undo, please make your own choice +inoremap coc#pum#visible() ? coc#pum#confirm() + \: "\u\\=coc#on_enter()\" + +nmap gp (coc-diagnostic-prev) +nmap gn (coc-diagnostic-next) + +" GoTo code navigation +nmap gd (coc-definition) +nmap gy (coc-type-definition) +nmap gi (coc-implementation) +nmap gr (coc-references) + +" Use K to show documentation in preview window +nnoremap gh :call ShowDocumentation() + +function! ShowDocumentation() + if CocAction('hasProvider', 'hover') + call CocActionAsync('doHover') + else + call feedkeys('K', 'in') + endif +endfunction + +" Highlight the symbol and its references when holding the cursor +autocmd CursorHold * silent call CocActionAsync('highlight') + +" Symbol renaming +nmap gR (coc-rename) + +" Formatting selected code +xmap gf (coc-format-selected) +nmap gf (coc-format-selected) diff --git a/vim/options.vim b/vim/options.vim index 7ffd2a9..650df04 100644 --- a/vim/options.vim +++ b/vim/options.vim @@ -6,8 +6,9 @@ set hlsearch " Highlight all match search pattern " Graphics options syntax on " Show syntax color +set termguicolors set background=dark " Set vim style as dark -colorscheme onedark " Set colorscheme as onedark +colorscheme zenwritten " Set colorscheme as onedark set number " Show line number set relativenumber " Show relative line number set cursorline " Select the current line @@ -44,6 +45,7 @@ set updatetime=500 " Delay before vim write swap file, lower better for gitgutte " Autocomplete set completeopt=menu,menuone,popup,noselect,noinsert " Show a pop up for command completion set wildmenu " Turn on wildmenu +filetype plugin on " Avoid garbled characters in Chinese language windows OS let $LANG='en' " Setting lang as en diff --git a/vim/plugins.vim b/vim/plugins.vim index 7822826..a32da64 100644 --- a/vim/plugins.vim +++ b/vim/plugins.vim @@ -16,16 +16,14 @@ call plug#begin('~/.vim/plugged') " UI & Themes Plug 'joshdick/onedark.vim' " Onedark themes for vim +Plug 'mcchrish/zenbones.nvim' " White / dark colorscheme Plug 'liuchengxu/vim-which-key' " Show leader mapping cheatsheet " Git integration Plug 'airblade/vim-gitgutter' " Git diff " Autocompletion, linter, syntax -Plug 'prabirshrestha/vim-lsp' " Linter & formatter -Plug 'mattn/vim-lsp-settings' " Automatic vim-lsp installation -Plug 'prabirshrestha/asyncomplete.vim' " Autocompletion -Plug 'prabirshrestha/asyncomplete-lsp.vim' " Autocompletion & connection with vim-lsp +Plug 'neoclide/coc.nvim', {'branch': 'release'} " Tools Plug 'wakatime/vim-wakatime' " Wakatime @@ -71,9 +69,6 @@ set statusline+=\ \|\ [%{&fileformat}\] set statusline+=\ \|\ %l:%c set statusline+=\ [%p%%]\ -" VIM lsp -let g:lsp_diagnostics_echo_cursor = 1 -let g:lsp_diagnostics_virtual_text_enabled = 0 " Which Key call which_key#register('', "g:which_key_map") @@ -123,16 +118,15 @@ let g:which_key_map.h = { \ } " LSP key help -let g:which_key_map.l = { +let g:which_key_map.g = { \ 'name' : '+LSP', \ 'd' : 'go to definition', - \ 'nd' : 'next diagnostic', - \ 'pd' : 'previous diagnostic', - \ 'f' : 'go to reference', - \ 'r' : 'rename object', - \ 's' : 'stop LSP server', - \ 'p' : 'peek definition', - \ 'a' : 'code action', - \ 'h' : 'hover information', - \ 'df' : 'format document', + \ 'n' : 'next diagnostic', + \ 'p' : 'previous diagnostic', + \ 'r' : 'go to reference', + \ 'R' : 'rename object', + \ 'y' : 'type definition', + \ 'i' : 'go to implementation', + \ 'h' : 'documentation', + \ 'f' : 'format document', \ } -- cgit v1.2.3