neo-tree.nvim
neo-tree.nvim copied to clipboard
BUG: Need to open file twice when opening neovim with "nvim ."
Did you check docs and existing issues?
- [X] I have read all the docs.
- [X] I have searched the existing issues.
- [X] I have searched the existing discussions.
Neovim Version (nvim -v)
0.9.4
Operating System / Version
Archlinux / linux 6.5.7.arch1-1
Describe the Bug
When I open neovim with "nvim ." I need to open a file twice for it to actually be opened in a buffer.
Screenshots, Traceback
No response
Steps to Reproduce
- nvim .
-
e to open neotree - Enter to open a file
- The file contents flashes in the buffer and then dissapears.
- <C-w><C-w> to focus neotree again
- Enter to oten file
- File contents are opened into buffer
Expected Behavior
- nvim .
-
e to open neotree - Enter to open a file
- File contents are opened into buffer
Your Configuration
vim.g.loaded_netrwPlugin = 1
vim.g.loaded_netrw = 1
vim.g.mapleader = ' '
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)
require('lazy').setup({
{
'nvim-neo-tree/neo-tree.nvim',
branch = 'v3.x',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended
'MunifTanjim/nui.nvim',
},
},
}, {})
vim.keymap.set(
'n',
'<leader>e',
':Neotree<CR>'
)
It was solved by setting hijack_netrw_behavior = "disabled"
:
return {
'nvim-neo-tree/neo-tree.nvim',
branch = 'v3.x',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended
'MunifTanjim/nui.nvim',
},
config = function()
require("neo-tree").setup({
filesystem = {
hijack_netrw_behavior = "disabled"
}
})
end,
}
Maybe related: #907?
This is caused by neo-tree lazy-loaded by lazy.nvim and only been invoked after you pressed <Leader>e
with the keys
keyword.
The most intuitive way to solve this issue would be to load neo-tree on startup when nvim .
.
return {
"nvim-neo-tree/neo-tree.nvim",
dependencies = {
{ "MunifTanjim/nui.nvim" },
{ "nvim-tree/nvim-web-devicons" },
},
cmd = { "Neotree" },
keys = {
{ "<Leader>e", "<Cmd>Neotree toggle<CR>", remap = false, silent = true, desc = "<Cmd>Neotree toggle<CR>" },
},
init = function()
vim.g.neo_tree_remove_legacy_commands = 1
---@type string[]
local argv = vim.fn.argv() or {} ---@diagnostic disable-line
if vim.tbl_contains(argv, ".") then -- load neo-tree when `nvim .`
vim.schedule(function()
pcall(require, "neo-tree")
end)
end
end,
opts = {
-- ..
},
}
With the above configuration, you don't need to hijack_netrw_behavior = "disabled"
as well.
Does the above solution work for you @jakkan ?
Thanks for the suggested solution above. Unfortunately, it doesn't seem to work for me. However, using hijack_netrw_behavior = "disabled" still works well. Given this, I think we can consider this issue resolved.