Feature/fzf commands (#4)

* vimrc: fix signcolumn, prune quickfix,netrw buffers from list

* vimrc: add FZF shortcuts, overrides

* vimrc: improvements to coc.nvim, check for node
This commit is contained in:
Paul Stemmet 2021-08-08 20:22:07 +01:00 committed by GitHub
parent 05e3ef0cc1
commit a45652fd2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 66 additions and 9 deletions

75
vimrc
View File

@ -68,16 +68,16 @@ set completeopt+=longest
" Lower update time (Default 4000)
set updatetime=300
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set number
set relativenumber
try
" Vim 8.2 only
set signcolumn=number
set signcolumn=auto
catch
set signcolumn=yes:1
endtry
set number
set relativenumber
" Use existing buffers
set switchbuf="useopen,usetab"
if exists('+termguicolors')
set termguicolors
@ -106,12 +106,12 @@ call plug#begin("$VIMHOME/plugged")
Plug 'Xuyuanp/nerdtree-git-plugin', { 'on': 'NERDTreeToggle' }
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/vim-statline'
Plug 'qpkorr/vim-bufkill'
Plug 'vim-perl/vim-perl', { 'for': 'perl', 'do': 'make clean carp dancer highlight-all-pragmas moose test-more try-tiny' }
Plug 'rust-lang/rust.vim', { 'for': 'rust' }
Plug 'pearofducks/ansible-vim', { 'for': ['yaml', 'yml'] }
Plug 'luochen1990/rainbow'
Plug 'kevinoid/vim-jsonc'
Plug 'jremmen/vim-ripgrep', { 'on': ['Rg', 'RgRoot'] }
Plug 'junegunn/fzf', { 'on': ['FZF', '<Plug>fzf#run', '<Plug>fzf#wrap'] }
Plug 'junegunn/fzf.vim'
Plug 'sheerun/vim-polyglot'
@ -243,12 +243,33 @@ augroup PsoxFileAutos
\| endif
if has_key(plugs, 'coc.nvim')
" Highlight the symbol and its references when hovering
autocmd CursorHold * silent call CocActionAsync('highlight')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
endif
" Force non file buffers to not pollute the buffer list
autocmd FileType quickfix,netrw setlocal nobuflisted
" Actually kill netrw when trying to quit it
autocmd FileType netrw nnoremap <buffer><silent> <Esc> :call <SID>CloseNetrw()<CR>
augroup END
function! s:CloseNetrw() abort
for bufn in range(1, bufnr('$'))
if bufexists(bufn) && getbufvar(bufn, '&filetype') ==# 'netrw'
silent! execute 'bwipeout ' . bufn
if getline(2) =~# '^" Netrw '
silent! bwipeout
endif
return
endif
endfor
endfunction
" Set bindings for coc.nvim
if has_key(plugs, 'coc.nvim')
if has_key(plugs, 'coc.nvim') && executable("node")
if !exists("g:coc_global_extensions")
let g:coc_global_extensions=[]
endif
@ -267,6 +288,12 @@ if has_key(plugs, 'coc.nvim')
nmap <silent> <leader>/ <Plug>(coc-codeaction-selected)
xmap <silent> <leader>/ <Plug>(coc-codeaction-selected)
" rename symbol
nnoremap <silent> <leader>rn <Plug>(coc-rename)
" goto definition / references
nnoremap <silent> <leader>gd <Plug>(coc-definition)
nnoremap <silent> <leader>gr <Plug>(coc-references)
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
@ -317,6 +344,36 @@ if has_key(plugs, 'coc.nvim')
nnoremap <silent> <C-Y> :<C-u>CocList -A --normal yank<CR>
endif
" FZF overides
if has_key(plugs, 'fzf.vim')
if executable('rg')
" Only search file contents, not file name
" We can use the stock :Files for that
command! -bang -nargs=* Rg call
\ fzf#vim#grep(
\ "rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}),
\ <bang>0
\ )
" Override the default grep implementation in vim
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
" If the user hasn't set a default FZF command, and has ripgrep installed,
" use it over find, otherwise defer to the user's preferred command
if empty($FZF_DEFAULT_COMMAND)
command! -bang -nargs=? -complete=dir Files call
\ fzf#vim#files(<q-args>, fzf#vim#with_preview({'source': 'rg --files --hidden --glob "!**/.git/**" ' }), <bang>0)
endif
nnoremap <silent> <A-g> :Rg<CR>
endif
nnoremap <silent> <A-f> :Files<CR>
nnoremap <silent> <A-b> :Buffers<CR>
endif
" Vim Tmux unified movement
if has_key(plugs, 'vim-tmux-navigator')
let g:tmux_navigator_no_mappings = 1
@ -347,7 +404,7 @@ function! ToggleGutter() abort
exec "set nonumber norelativenumber signcolumn=no"
else
exec "set number relativenumber"
try | set signcolumn=number | catch | set signcolumn=yes:1 | endtry
try | set signcolumn=auto | catch | set signcolumn=yes:1 | endtry
endif
endfunction