From 083cfa3c20fc7e3cd6f0c031bbcd543044ff4753 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 25 Feb 2020 23:25:25 +0100 Subject: [PATCH] [nvim] Change fzf to use floating window By default fzf now uses a floating window covering most of the editor screen real estate. It can still be full screened with a bang. Floating window can be made optional with fzf layout options, but for now I will try it for all fzf searches to get a feel for the positives and negatives. --- nvim/.config/nvim/plugin/fzf.vim | 37 +++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/nvim/.config/nvim/plugin/fzf.vim b/nvim/.config/nvim/plugin/fzf.vim index 77eb58a..256874a 100644 --- a/nvim/.config/nvim/plugin/fzf.vim +++ b/nvim/.config/nvim/plugin/fzf.vim @@ -1,7 +1,5 @@ " PLUGIN: fzf.vim " set some fzf defaults -" windows drops down from above, 40% of the screen -let g:fzf_layout = { 'up': '~40%' } " any Fzf command is prefixed with Fzf " this groups them nicely together, and avoids confusion when suddenly :Buffer " or :Files would appear as a command otherwise @@ -13,6 +11,7 @@ let g:fzf_colors = \ 'hl': ['fg', 'Comment'], \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], + \ 'gutter': ['bg', 'Normal'], \ 'hl+': ['fg', 'Statement'], \ 'info': ['fg', 'PreProc'], \ 'border': ['fg', 'Ignore'], @@ -30,5 +29,37 @@ let g:fzf_action = { " FzfRg but also search through hidden files command! -bang -nargs=* FzfRgHidden \ call fzf#vim#grep( - \ 'rg --column --line-number --no-heading --color=always --smart-case --hidden '.shellescape(), 1, + \ "rg --column --line-number --no-heading --color=always --smart-case --hidden --glob '!.git' ".shellescape(), 1, \ fzf#vim#with_preview(), 0) + +" make fzf use the nvim floating window globally. (weee, technology!) +" +let $FZF_DEFAULT_OPTS="--layout=reverse --margin=1,2" +" to use fzf in a floating window only conditionally, the best approach would +" probably be call fzf#run(fzf#wrap({ 'window': 'call FloatingFZF()' })) for +" every command we want to floatize +let g:fzf_layout = { 'window': 'call FloatingFZF()' } + +function! FloatingFZF() + " create a minimal nofile scratch buffer + let buf = nvim_create_buf(v:false, v:true) + call setbufvar(buf, '&signcolumn', 'no') + + " this should probably change depending on fzf command + let height = float2nr(50) + let width = float2nr(200) + " center the window in editor + let horizontal = float2nr((&columns - width) / 2) + let vertical = float2nr((&lines - height) / 2) + + let opts = { + \ 'relative': 'editor', + \ 'row': vertical, + \ 'col': horizontal, + \ 'width': width, + \ 'height': height, + \ 'style': 'minimal' + \ } + + call nvim_open_win(buf, v:true, opts) +endfunction