From 1bfe1a22326878e600fcef15bc2e0db6e01e9d25 Mon Sep 17 00:00:00 2001 From: Malte Brandy Date: Fri, 7 Jan 2022 14:39:41 +0100 Subject: [PATCH] Improve vim config --- home-manager/roles/neovim/vimrc | 82 +++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/home-manager/roles/neovim/vimrc b/home-manager/roles/neovim/vimrc index 757d56c1..e5e4703c 100644 --- a/home-manager/roles/neovim/vimrc +++ b/home-manager/roles/neovim/vimrc @@ -5,9 +5,17 @@ let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#nvimlsp#enabled = 0 let g:tex_flavor = 'latex' -nmap e :CocCommand explorer --no-toggle +function! MyExplorer() + if &filetype == 'coc-explorer' + wincmd w + else + CocCommand explorer --no-toggle + endif +endfunction -set foldcolumn=1 +nnoremap e :call MyExplorer() + +set nofoldenable set background=light set autoindent set nosmartindent @@ -124,20 +132,20 @@ inoremap coc#refresh() " Coc only does snippet and additional edit on confirm. inoremap pumvisible() ? "\" : "\u\" -nmap gp (coc-diagnostic-prev) -nmap gn (coc-diagnostic-next) +nnoremap gp (coc-diagnostic-prev) +nnoremap gn (coc-diagnostic-next) " Remap keys for gotos -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gr (coc-references) +nnoremap gd (coc-definition) +nnoremap gy (coc-type-definition) +nnoremap gr (coc-references) -nmap gs :Git status -nmap gu :CocCommand git.chunkUndo -nmap gi :CocCommand git.chunkInfo -nmap ga :CocCommand git.chunkStage -nmap gb :CocCommand git.showCommit -nmap gc :Git commit +nnoremap gs :Git status +nnoremap gu :CocCommand git.chunkUndo +nnoremap gi :CocCommand git.chunkInfo +nnoremap ga :CocCommand git.chunkStage +nnoremap gb :CocCommand git.showCommit +nnoremap gc :Git commit function! s:show_documentation() if (index(['vim','help'], &filetype) >= 0) @@ -148,14 +156,14 @@ function! s:show_documentation() endif endfunction -nmap i :call show_documentation() +nnoremap i :call show_documentation() " Remap for rename current word -nmap r (coc-rename) +nnoremap r (coc-rename) " Remap for format selected region xmap f (coc-format-selected) -nmap f (coc-format-selected) +nnoremap f (coc-format-selected) augroup mygroup autocmd! @@ -167,9 +175,9 @@ augroup end " Remap for do codeAction of selected region, ex: `aap` for current paragraph xmap a (coc-codeaction-selected) -nmap a (coc-codeaction-selected) -nmap f :Format -nmap l (coc-codelens-action) +nnoremap a (coc-codeaction-selected) +nnoremap f :Format +nnoremap l (coc-codelens-action) " Create mappings for function text object, requires document symbols feature of languageserver. @@ -179,13 +187,31 @@ omap if (coc-funcobj-i) omap af (coc-funcobj-a) " FZF ctrl-p style search -nmap p :Files -nmap g :Rg -nmap h :History -nmap b :Buffers -nmap k :qa -nmap q :q -nmap s :w +nnoremap p :Files +nnoremap g :Rg +nnoremap h :History +nnoremap b :Buffers + +function MyClose() + if &readonly + quit + else + write + quit + endif +endfunction + +function MyCloseAll() + if &readonly + quitall + else + wall + quitall + endif +endfunction +nnoremap q :call MyClose() +nnoremap k :call MyCloseAll() +nnoremap s :w nnoremap :bp nnoremap :bn @@ -211,7 +237,7 @@ inoremap :bn "let g:fzf_layout = { 'window': 'call FloatingFZF()' } " Use for select selections ranges, needs server support, like: coc-tsserver, coc-python -nmap (coc-range-select) +nnoremap (coc-range-select) xmap (coc-range-select) xmap (coc-range-select-backword) @@ -239,8 +265,6 @@ nnoremap o :CocFzfList outline nnoremap a :CocFzfList actions " Do default action for next item. nnoremap j :CocNext -" Do default action for previous item. -nnoremap k :CocPrev imap