From a476b885a5a7166735e4aeb7d438da4c1998fc57 Mon Sep 17 00:00:00 2001 From: serxoz Date: Fri, 5 Nov 2021 09:23:45 +0100 Subject: [PATCH] fzf --- nvim/.config/nvim/init.vim | 84 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index f3610d2..2e3717b 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -103,6 +103,9 @@ Plug 'kabouzeid/nvim-lspinstall' Plug 'nvim-lua/completion-nvim' Plug 'glepnir/lspsaga.nvim' +Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } +Plug 'junegunn/fzf.vim' +Plug 'airblade/vim-rooter' call plug#end() " fin de la instalciĆ³n de pluggins @@ -150,7 +153,6 @@ EOF " LSP configuracion set completeopt=menuone,noinsert,noselect let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy'] - lua < g gg=G vnoremap J :m '>+1gv=gv vnoremap K :m '<-2gv=gv - """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " POR HACER """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -192,4 +193,81 @@ vnoremap K :m '<-2gv=gv " linter " " sistema para buscar: telescope, harpoon, fuzzyfinder, grep... -" + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" FZF Config +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" https://www.chrisatmachine.com/Neovim/08-fzf/ +" Dependencias: fzf ripgrep universal-ctags silversearcher-ag fd +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" This is the default extra key bindings +let g:fzf_action = { + \ 'ctrl-t': 'tab split', + \ 'ctrl-x': 'split', + \ 'ctrl-v': 'vsplit' } + +" Enable per-command history. +" CTRL-N and CTRL-P will be automatically bound to next-history and +" previous-history instead of down and up. If you don't like the change, +" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS. +let g:fzf_history_dir = '~/.local/share/fzf-history' + +nnoremap ff :Files +nnoremap fb :Buffers +nnoremap fg :Rg +nnoremap ft :Tags +nnoremap fm :Marks + +let g:fzf_tags_command = 'ctags -R' +" Border color +let g:fzf_layout = {'up':'~90%', 'window': { 'width': 0.8, 'height': 0.8,'yoffset':0.5,'xoffset': 0.5, 'highlight': 'Todo', 'border': 'sharp' } } + +let $FZF_DEFAULT_OPTS = '--layout=reverse --info=inline' +let $FZF_DEFAULT_COMMAND="rg --files --hidden" + + +" Customize fzf colors to match your color scheme +let g:fzf_colors = +\ { 'fg': ['fg', 'Normal'], + \ 'bg': ['bg', 'Normal'], + \ 'hl': ['fg', 'Comment'], + \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], + \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], + \ 'hl+': ['fg', 'Statement'], + \ 'info': ['fg', 'PreProc'], + \ 'border': ['fg', 'Ignore'], + \ 'prompt': ['fg', 'Conditional'], + \ 'pointer': ['fg', 'Exception'], + \ 'marker': ['fg', 'Keyword'], + \ 'spinner': ['fg', 'Label'], + \ 'header': ['fg', 'Comment'] } + +"Get Files +command! -bang -nargs=? -complete=dir Files + \ call fzf#vim#files(, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline']}), 0) + + +" Get text in files with Rg +command! -bang -nargs=* Rg + \ call fzf#vim#grep( + \ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(), 1, + \ fzf#vim#with_preview(), 0) + +" Ripgrep advanced +function! RipgrepFzf(query, fullscreen) + let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true' + let initial_command = printf(command_fmt, shellescape(a:query)) + let reload_command = printf(command_fmt, '{q}') + let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]} + call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen) +endfunction + +command! -nargs=* -bang RG call RipgrepFzf(, 0) + +" Git grep +command! -bang -nargs=* GGrep + \ call fzf#vim#grep( + \ 'git grep --line-number '.shellescape(), 0, + \ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), 0) +