[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.
This commit is contained in:
Marty Oehme 2020-02-25 23:25:25 +01:00
parent fcd58887da
commit 083cfa3c20
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A

View file

@ -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(<q-args>), 1,
\ "rg --column --line-number --no-heading --color=always --smart-case --hidden --glob '!.git' ".shellescape(<q-args>), 1,
\ fzf#vim#with_preview(), <bang>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