New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Floating Windows Support From Neovim #664
Comments
You can pass an arbitrary command as function! Foo()
tabnew
" or whatever
endfunction
call fzf#run({'window': 'call Foo()'}) See https://github.com/junegunn/fzf/blob/master/README-VIM.md#fzfrun for details. |
@junegunn Thanks a bunch |
function! Foo()
if exists('*nvim_open_float_win')
let b = nvim_create_buf(v:false)
call nvim_buf_set_option(b, "buftype", "nofile")
call nvim_buf_set_lines(b,0,-1,v:true,["test"])
let opts = {'x':100, 'y':5, 'anchor': 'NE'}
let w = nvim_open_float_win(b,v:false,60,20,opts)
hi Floating guibg=#000000
call setwinvar(w, '&winhl', 'Normal:Floating')
call setwinvar(w, '&number', 0)
endif
endfunction
call fzf#run({'window': 'call Foo()'})
I tried the following script, but fzf windows is not opened inside the floating windows, any idea? How does fzf window option locate the window? |
It opens in the "current" window where your cursor is positioned. |
@Piping change v:false to v:true in the open float call. |
I got a nice result with the following: let g:fzf_layout = { 'window': 'call FloatingFZF()' }
function! FloatingFZF()
let buf = nvim_create_buf(v:false, v:true)
call setbufvar(buf, '&signcolumn', 'no')
let winheight = winheight(0)
let winwidth = winwidth(0)
let width = float2nr(winwidth-(winwidth*2/10))
let opts = {
\ 'relative': 'editor',
\ 'row': &lines - 3,
\ 'col': float2nr((winwidth-width)/2),
\ 'width': width,
\ 'height': &lines - 3
\ }
call nvim_open_win(buf, v:true, opts)
endfunction I was trying to achieve a different visual with the "input" in the top and the list of files in a top-down layout, but with the current fzf customization tools I didn't find a way to do it. |
little change to keep the floating window centralized horizontally, regardless of any vertical splits. function! FloatingFZF()
let buf = nvim_create_buf(v:false, v:true)
call setbufvar(buf, '&signcolumn', 'no')
let width = float2nr(&columns - (&columns * 2 / 10))
let height = &lines - 3
let y = &lines - 3
let x = float2nr((&columns - width) / 2)
let opts = {
\ 'relative': 'editor',
\ 'row': y,
\ 'col': x,
\ 'width': width,
\ 'height': height
\ }
call nvim_open_win(buf, v:true, opts)
endfunction |
See |
Thanks @junegunn, I got the visual that I wanted: let $FZF_DEFAULT_OPTS='--layout=reverse'
let g:fzf_layout = { 'window': 'call FloatingFZF()' }
function! FloatingFZF()
let buf = nvim_create_buf(v:false, v:true)
call setbufvar(buf, '&signcolumn', 'no')
let height = &lines - 3
let width = float2nr(&columns - (&columns * 2 / 10))
let col = float2nr((&columns - width) / 2)
let opts = {
\ 'relative': 'editor',
\ 'row': 1,
\ 'col': col,
\ 'width': width,
\ 'height': height
\ }
call nvim_open_win(buf, v:true, opts)
endfunction |
@kassio hi i use this function, how to hide line number in float window? |
change
to
|
@sassanh nothing change. |
It's working for me:
And this (not changing anything in the function):
|
You can use: au FileType fzf set nonu nornu Just saw that @sassanh already mention that, sorry for the noise. |
Put this at the end of your
|
Hi @kassio Thanks for the cool tips, do you know how can I get ride of that annoying Flashing background color when I open fzf ? |
" floating fzf
if has('nvim')
let $FZF_DEFAULT_OPTS .= ' --layout=reverse'
function! FloatingFZF()
let buf = nvim_create_buf(v:false, v:true)
" here be dragoons
let height = &lines
let width = float2nr(&columns - (&columns * 2 / 10))
let col = float2nr((&columns - width) / 2)
let col_offset = &columns / 10
let opts = {
\ 'relative': 'editor',
\ 'row': 1,
\ 'col': col + col_offset,
\ 'width': width * 2 / 1,
\ 'height': height / 2
\ }
let win = nvim_open_win(buf, v:true, opts)
call setwinvar(win, '&winhl', 'NormalFloat:TabLine')
" this is to remove all line numbers and so on from the window
setlocal
\ buftype=nofile
\ nobuflisted
\ bufhidden=hide
\ nonumber
\ norelativenumber
\ signcolumn=no
endfunction
let g:fzf_layout = { 'window': 'call FloatingFZF()' }
endif
this is a mix from junegunn dotfiles, comment from this thread and space-vim config if you guys have better alternatives do share here ! |
|
@AhmedAbdulrahman is that still happening? For me, it's not happening. 🤷♂ |
changed it! why is it better? |
You usually don't need the " floating fzf
if has('nvim')
let $FZF_DEFAULT_OPTS .= ' --layout=reverse'
function! FloatingFZF()
let height = &lines
let width = float2nr(&columns - (&columns * 2 / 10))
let col = float2nr((&columns - width) / 2)
let col_offset = &columns / 10
let opts = {
\ 'relative': 'editor',
\ 'row': 1,
\ 'col': col + col_offset,
\ 'width': width * 2 / 1,
\ 'height': height / 2,
\ 'style': 'minimal'
\ }
let buf = nvim_create_buf(v:false, v:true)
let win = nvim_open_win(buf, v:true, opts)
call setwinvar(win, '&winhl', 'NormalFloat:TabLine')
endfunction
let g:fzf_layout = { 'window': 'call FloatingFZF()' }
endif |
How would I change the background color for the FloatWindow in @alfunx example? |
@nstetter If you want to change the color for all floating windows and just use that color, set the call setwinvar(win, '&winhl', 'NormalFloat:TabLine') If you want to use a different colors for that specific floating window (while leaving the other ones as they are now), exchange call setwinvar(win, '&winhl', 'NormalFloat:Error') You can also define a highlighting group yourself and then use that, e.g. highlight SpecificFloat ctermbg=... ctermfg=... |
Hi @junegunn
Neovim patch from @bfredl has a working version of floating windows implementation now.
Is it possible to add a
split direction
likefloat
and then open fzf inside floating windows.Here is a reference
The text was updated successfully, but these errors were encountered: