Skip to content

[vim] Move and resize popup window when detecting VimResized event #4778

Closed

Description

@Vulcalien

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.71.0 (62899fd)

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

This isn't meant to be an issue, rather a pull request.

I have already made the changes that fix the issue I'm about to present. See this commit in my fork.

The issue

The Vim plugin for fzf currently behaves poorly when the app is resized and fzf is a popup.

For example:

let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }

When opening this layout in a 80x24 terminal, the size of fzf is 72x14.
If we resize the terminal to a larger size, we would expect fzf to grow, but instead it stays at 72x14.
This behavior is shown perfectly by this video in fzf.vim.

The solution

Vim and Neovim offer a VimResized event and functions to resize and move popups/windows.

I introduce the s:resize_popup() function, which repeats the calculation of width/height/offset with the updated terminal size, and then moves and resizes the popup.

I've tested the changes on Vim (9.1) and Neovim (0.9.5).

Activity

  1. junegunn commented on Apr 18, 2026

    @junegunn
    Owner

    Thanks, I'll take a look.

  2. added
    enhancement
    neovim
    vim
    on Apr 19, 2026
  3. junegunn commented on Apr 19, 2026

    @junegunn
    Owner

    Thanks, it works well with Vim and Neovim. I have two questions on the patch:

    1. VimResized autocmd is never cleared. Is it possible to clear it when fzf terminates?
    2. Do we need a guard similar to nvim_win_is_valid in s:resize_popup for vim?
  4. junegunn commented on Apr 19, 2026

    @junegunn
    Owner

    Something like this?

    diff --git a/plugin/fzf.vim b/plugin/fzf.vim
    index 7499ba05..677f3560 100644
    --- a/plugin/fzf.vim
    +++ b/plugin/fzf.vim
    @@ -896,6 +896,7 @@ function! s:execute_term(dict, command, temps) abort
         endif
       endfunction
       function! fzf.on_exit(id, code, ...)
    +    silent! autocmd! fzf_popup_resize
         if s:getpos() == self.ppos " {'window': 'enew'}
           for [opt, val] in items(self.winopts)
             execute 'let' opt '=' val
    @@ -1050,11 +1051,12 @@ if has('nvim')
       endfunction
     
       function! s:resize_popup() abort
    -    if nvim_win_is_valid(s:popup_id)
    -      let opts = s:popup_bounds()
    -      let opts = extend({'relative': 'editor'}, opts)
    -      call nvim_win_set_config(s:popup_id, opts)
    +    if !exists('s:popup_id') || !nvim_win_is_valid(s:popup_id)
    +      return
         endif
    +    let opts = s:popup_bounds()
    +    let opts = extend({'relative': 'editor'}, opts)
    +    call nvim_win_set_config(s:popup_id, opts)
       endfunction
     else
       function! s:create_popup() abort
    @@ -1066,6 +1068,9 @@ else
       endfunction
     
       function! s:resize_popup() abort
    +    if !exists('s:popup_id') || empty(popup_getpos(s:popup_id))
    +      return
    +    endif
         let opts = s:popup_bounds()
         call popup_move(s:popup_id, {
           \ 'line': opts.row,
  5. Vulcalien commented on Apr 19, 2026

    @Vulcalien
    ContributorAuthor

    Glad it works! I'm unable to test the changes right now, but from the looks of it that should be all correct.

    I agree that clearing VimResized is better. As for a guard for Vim to check if the popup is valid, from what I understand popup_move does nothing if the popup is invalid. Still, safer to add a guard like you did.

    If everything works on your end, feel free to cherry pick my commit and add your changes.

  6. junegunn commented on Apr 19, 2026

    @junegunn
    Owner

    Merged to master. Thanks!

  7. added a commit that references this issue on Apr 19, 2026
    780a624
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementneovimvim

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions