-
Notifications
You must be signed in to change notification settings - Fork 267
Description
Did you check docs and existing issues?
- I have read all the docs.
- I have searched the existing issues.
- I have searched the existing discussions.
Neovim Version (nvim -v)
NVIM v0.9.2
Operating System / Version
Windows 11 22H2
Describe the Bug
When the close_if_last_window
option is enabled, the "swap to modified buffer" scheduled function in init.lua
causes the error E492: Not an editor command: ...
. This only happens for buffers of files on disk (not unnamed buffers), specifically on a Windows system. This does not occur on WSL for the same system.
Possible root cause:
Looking at the traceback, it looks like this occurs because the :b[uffer]
command is concatenating with an absolute Windows path (e.g., starting with a partition letter) resulting in an "unknown" command such as :bC:/...
(see line 310 below):
neo-tree.nvim/lua/neo-tree/setup/init.lua
Lines 306 to 311 in cfe1920
vim.schedule(function() | |
log.warn(message) | |
vim.cmd("rightbelow vertical split") | |
vim.api.nvim_win_set_width(win_id, state.window.width or 40) | |
vim.cmd("b" .. buf_name) | |
end) |
Example :b
test on Windows:
- Open a file in Neovim with
nvim C:/foo.txt
- Both
:b C:\foo.txt
and:b C:/foo.txt
work as expected - Both
:bC:\foo.txt
and:bC:/foo.txt
causes the errorE492: Not an editor command: bC:...
Screenshots, Traceback
Error executing vim.schedule lua callback: vim/_editor.lua:341: nvim_exec2(): Vim:E492: Not an editor command: bC:/Users/user/AppData/Local/nvim/lua/user/plugins/neo-tree.lua
stack traceback:
[C]: in function 'nvim_exec2'
vim/_editor.lua:341: in function 'cmd'
...nvim-data/lazy/neo-tree.nvim/lua/neo-tree/setup/init.lua:310: in function <...nvim-data/lazy/neo-tree.nvim/lua/neo-tree/setup/init.lua:306>
Steps to Reproduce
- Use Neovim on a Windows system with this plugin, minimally configured with
lazy
per README. Minimalinit.lua
provided below, but the following is the relevant plugin spec for neo-tree to create the behavior:
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"MunifTanjim/nui.nvim",
},
opts = { close_if_last_window = true },
}
- Open Neotree with
:Neotree filesystem reveal left
- Modify an existing file on disk without saving (IMPORTANT: the file must exist on disk since the buffer name will use an absolute Windows path)
- Attempt to close the buffer with
:q
and observe the error
Expected Behavior
The modified buffer is focused without causing an error.
Your Configuration
-- lazy
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- load neo-tree with appropriate options
require("lazy").setup({
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"MunifTanjim/nui.nvim",
},
opts = { close_if_last_window = true },
},
})