rmagatti / goto-preview

A small Neovim plugin for previewing definitions using floating windows.
Apache License 2.0
779 stars 27 forks source link

Setting on `post_open_hook` will be shared if I split window? #87

Closed fjchen7 closed 1 year ago

fjchen7 commented 1 year ago

Describe the bug I set some options and keymap in post_open_hook. However it still take effect when I split the file.

To Reproduce

require('goto-preview').setup {
  post_open_hook = function(bufnr, winnr)
    local bo = vim.bo[bufnr]
    local wo = vim.wo[winnr]
    bo.modifiable = false
    wo.relativenumber = false
    wo.scrolloff = 1
    local opts = { buffer = bufnr }
    set("n", "v", "<cmd>wincmd L<cr>", opts)
    set("n", "s", "<cmd>wincmd J<cr>", opts)
    set("n", "t", "<cmd>wincmd T<cr>", opts)
  end
}

After I press v or s to split float window, the changed options and keymap also takes effect on the new window. I can't modify file and can't use v/s/t in this case. That is very counterintuitive.

Expected behavior

Settings on post_open_hook only have effect on float window.

Additional context

Float window and the new split window share the same buffer. I think this is the root cause.

rmagatti commented 1 year ago

Yeah, you're setting buffer-local mappings. Those are scoped to a buffer, which can be shared between windows. I have opened feature requests with both neovim/neovim and vim/vim about having window-local mappings.

https://github.com/vim/vim/issues/9339 https://github.com/neovim/neovim/issues/16263

Closing this as its a known "issue" and is already being tracked in the proper channels.