1

I have a popup / floating window open which is normally used for temporary jobs, like searching the code or opening a quick REPL. Is it possible to turn that into a regular buffer? While I have it open, it does not show up in :buffers, so I can't just move it to another tab or open a split above the popup; it remains in the centre of my screen. In fact, if I move away using <C-W><C-J> or similar, I can't even move back using the opposite direction, and have to find and plug in a mouse to get back into the popup!

My particular use-case is to keep the search results from fzf.vim's Rg command so that I can return to them after browsing some matches. However, this should apply equally well to any other uses of floating windows / popups.

I see that vim-floaterm allows you to store and then return to floating terminal buffers, with some hackery searching by index for buffers, but I don't fully understand why this logic is correct or necessary:

" find **one** visible floaterm window
function! floaterm#window#find() abort
  let found_winnr = 0
  for winnr in range(1, winnr('$'))
    if getbufvar(winbufnr(winnr), '&filetype') ==# 'floaterm'
      let found_winnr = winnr
      break
    endif
  endfor
  return found_winnr
endfunction

Can anyone explain the use of winbufnr, and how to use this to move a popup, or implement generalized store / load behaviour of popups?

1
  • 1
    :h popup-buffer ... popups are very specialized and restricted buffers. While you might be able to bend them into submission it'll only be by chance not by design. – B Layer Apr 12 at 12:59
1

A bit of a hack, but if you can get the window ID of the popup (popup_create returns it; popup_locate or popup_list might help find it), you can get the buffer contents and create a new one:

const popup_winid = …
const popup_bufnr = winbufnr(popup_winid)
const lines = getbufline(popup_bufnr, 1, '$')
" do something with them, like:
new
put =lines
1delete

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.