Skip to content

fix(picker_ui): handle 'winfixbuf' when opening selected file#426

Merged
dmtrKovalenko merged 1 commit intodmtrKovalenko:mainfrom
beixiyo:fix/winfixbuf-edit
Apr 29, 2026
Merged

fix(picker_ui): handle 'winfixbuf' when opening selected file#426
dmtrKovalenko merged 1 commit intodmtrKovalenko:mainfrom
beixiyo:fix/winfixbuf-edit

Conversation

@beixiyo
Copy link
Copy Markdown
Contributor

@beixiyo beixiyo commented Apr 29, 2026

Problem

Selecting a file in the picker raises E1513 whenever the source window has winfixbuf enabled:

Vim(edit):E1513: Cannot switch buffer. 'winfixbuf' is enabled
  at lua/fff/picker_ui.lua:2478 (in M.select)

M.select's edit branch checks the current buffer's buftype / modifiable, but not the window-local winfixbuf option. :h winfixbuf is the documented mechanism (Neovim 0.10+) for pinning a window to its buffer; any code path that runs :edit must respect it, otherwise the picker becomes unusable from a pinned window.

Why this isn't an obscure edge case

winfixbuf is the official "pin this window" API, not a niche flag. It fires in realistic flows:

  • A user explicitly pins the current file (:set winfixbuf) to keep it as a reference while jumping around — and then opens the picker to look at something else.
  • Sessions / view files (:mksession, auto-session, etc.) restore winfixbuf from a previous session.
  • Plugins set winfixbuf on certain windows; if the picker's find_suitable_window happens to land on one of those windows, the same error fires even when the source window was a non-file buffer.

Other pickers (e.g. Telescope, Snacks.picker) already handle winfixbuf for this reason.

Reproduction (minimal)

  1. :edit any_file.lua
  2. :set winfixbuf
  3. Open the picker and select another file.

Expected: file opens. Actual: E1513, file is not opened.

Fix

  • Add a small helper window_has_winfixbuf(win) (pcall-guarded for Neovim < 0.10 where the option doesn't exist).
  • find_suitable_window: skip windows where winfixbuf is set, so we never redirect into a pinned window.
  • M.select's edit branch: treat winfixbuf on the current window like a non-modifiable buftype — try find_suitable_window first; if no suitable window exists, fall back to :split so the file still opens without clobbering the pinned window.

Default path (no winfixbuf anywhere) is unchanged: :edit replaces the current buffer as before.

Test scenarios verified

  • No winfixbuf → edit replaces current buffer (regression check, default path unchanged)
  • Single window with winfixbuf → falls back to :split, original window keeps its pinned buffer
  • Multiple windows, current is winfixbuf + another normal window exists → switches to the normal window and :edit
  • Quickfix open + main window winfixbuf → split fallback, no error
  • :set nowinfixbuf after fix → behavior identical to default path

Notes

  • No new dependencies, no behavior change for users not using winfixbuf.
  • pcall around nvim_get_option_value('winfixbuf', ...) keeps the patch safe on Neovim versions predating the option.

When the current window has 'winfixbuf' enabled (Neovim 0.10+),
:edit fails with E1513. Detect this case in M.select's 'edit' branch
and either retarget a suitable non-fixed window or fall back to :split.
Also extend find_suitable_window to skip windows with 'winfixbuf'.

Fixes the following error when invoking the picker from a winfixbuf-locked window:
  E1513: Cannot switch buffer. 'winfixbuf' is enabled
@dmtrKovalenko dmtrKovalenko merged commit 37bda06 into dmtrKovalenko:main Apr 29, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants