nvim-tree / nvim-tree/nvim-tree.lua

Creating a file in deeply nested folders resets nvim-tree scroll position

Open
#3,164 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

invalid
Dominant language
Lua
Stars
8.6k
Forks
639
Avg merge
1d 14h
Merged PRs (30d)
2

Description

Description

Bug Description

When creating a new file in nvim-tree using the a key, the prompt opens as expected. However, as I type the file name, the cursor keeps jumping back to the beginning of the input, making it impossible to enter the full file name.

Neovim version
NVIM v0.11.0
Build type: Release
LuaJIT 2.1.1744318430
Operating system and version

Macos

Windows variant

No response

nvim-tree version

HEAD

Clean room replication
return {
	"nvim-tree/nvim-tree.lua",
	commit = "HEAD",

	dependencies = {
		"nvim-tree/nvim-web-devicons",
		"ryanoasis/vim-devicons",
		"folke/which-key.nvim",
	},
	config = function()
		local api = require("nvim-tree.api")

		-- Toggle с <Tab>
		vim.keymap.set(
			"n",
			"<Tab>",
			api.tree.toggle,
			{ desc = "Toggle NvimTree" }
		)

		require("which-key").add({
			{
				"<leader>e",
				function()
					vim.cmd("cd %:p:h")
					vim.cmd("pwd")
					api.tree.toggle({
						path = vim.fn.expand("%:p:h"),
						find_file = false,
					})
				end,
				desc = "Nvim-tree: setup",
			},
		})

		local function my_on_attach(bufnr)
			local function opts(desc)
				return {
					desc = "NvimTree: " .. desc,
					buffer = bufnr,
					noremap = true,
					silent = true,
					nowait = true,
				}
			end

			api.config.mappings.default_on_attach(bufnr)

			vim.keymap.set("n", "<C-o>", function()
				local node =
					require("nvim-tree.api").tree.get_node_under_cursor()
				if not node or not node.absolute_path then
					vim.notify("No file under cursor", vim.log.levels.WARN)
					return
				end
				vim.fn.jobstart(
					{ "open", "-R", node.absolute_path },
					{ detach = true }
				)
			end, opts("Reveal in Finder"))

			vim.keymap.set("n", "<Tab>", api.tree.toggle, opts("Toggle"))
			vim.keymap.set(
				"n",
				"<CR>",
				api.node.open.preview,
				opts("Preview file")
			)
			vim.keymap.set("n", "s", api.node.open.horizontal, opts("Split"))
			vim.keymap.set("n", "v", api.node.open.vertical, opts("VSplit"))
			vim.keymap.set("n", "p", api.tree.change_root_to_parent, opts("Up"))
			vim.keymap.set(
				"n",
				"c",
				api.tree.collapse_all,
				opts("Collapse all")
			)
			vim.keymap.set(
				"n",
				"gm",
				api.marks.bulk.move,
				opts("Bulk Move Marked Files")
			)
		end

		vim.g.loaded_netrw = 1
		vim.g.loaded_netrwPlugin = 1

		require("nvim-tree").setup({
			on_attach = my_on_attach,
			disable_netrw = true,
			hijack_cursor = true,
			update_focused_file = {
				enable = true,
				update_cwd = false,
			},
			renderer = {
				indent_markers = {
					enable = true,
				},
				icons = {
					webdev_colors = true,
					show = {
						file = true,
						folder = true,
						folder_arrow = true,
						git = true,
					},
				},
			},
			filters = {
				dotfiles = true,
				custom = { "node_modules" },
			},
			diagnostics = {
				enable = true,
				show_on_dirs = true,
			},
			git = {
				enable = true,
				ignore = true,
				show_on_dirs = true,
			},
			view = {
				width = 30,
				side = "left",
				preserve_window_proportions = true,
			},
		})
	end,
}
Steps to reproduce
  1. Open nvim-tree
  2. Press a to create a file
  3. Start typing something like: Users/antonarlazarov/GG Freight Services/Daily Notes/2025/July/test.md
  4. After typing a few characters, the cursor jumps to the start of the line, and continues to reset on every keystroke.
Expected behavior

The cursor should remain at the end of the input as the user types, allowing a full path or long file name to be entered without interruption.

Actual behavior

After typing a few characters, the cursor jumps to the start of the line, and continues to reset on every keystroke.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. First reproduce the issue with nvim-tree's a action and the nested path from the report, then trace the file-creation prompt and its input updates. Done means the cursor stays at the end while typing long paths, with focused coverage for this behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.