[nvim] Simplify floating fzf window

fzf already comes with its own floating window call function, so we
don't have to use our own. Instead simply call the floating window when
we are in compatible vim/nvim version and let fzf do its thing.
This commit is contained in:
Marty Oehme 2020-02-27 10:06:38 +01:00
parent 3575c147b2
commit a390d14390
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A

View file

@ -34,32 +34,15 @@ command! -bang -nargs=* FzfRgHidden
" make fzf use the nvim floating window globally. (weee, technology!) " make fzf use the nvim floating window globally. (weee, technology!)
" "
let $FZF_DEFAULT_OPTS="--layout=reverse --margin=1,2" let $FZF_DEFAULT_OPTS="--layout=reverse "
" to use fzf in a floating window only conditionally, the best approach would " 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 " every command we want to floatize
let g:fzf_layout = { 'window': 'call FloatingFZF()' } if has('nvim-0.4.0') || has("patch-8.2.0191")
let g:fzf_layout = { 'window': {
function! FloatingFZF() \ 'width': 0.7,
" create a minimal nofile scratch buffer \ 'height': 0.7,
let buf = nvim_create_buf(v:false, v:true) \ 'highlight': 'PreProc',
call setbufvar(buf, '&signcolumn', 'no') \ 'border': 'rounded' } }
else " Fallback to a split window
" this should probably change depending on fzf command let g:fzf_layout = { "window": "silent botright 16split enew" }
let height = float2nr(50) endif
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