Nvim-tree Issues #2807
Replies: 7 comments 2 replies
-
also the function M.stage_file()
local node = api.tree.get_node_under_cursor()
local gs = node.git_status.file
-- If the current node is a directory get children status
if gs == nil then
gs = (node.git_status.dir.direct ~= nil and node.git_status.dir.direct[1])
or (node.git_status.dir.indirect ~= nil and node.git_status.dir.indirect[1])
end
-- If the file is untracked, unstaged or partially staged, we stage it
if gs == "??" or gs == "MM" or gs == "AM" or gs == " M" then
vim.cmd("silent !git add " .. node.absolute_path)
-- If the file is staged, we unstage
elseif gs == "M " or gs == "A " then
vim.cmd("silent !git restore --staged " .. node.absolute_path)
end
api.tree.reload()
end it does the reload thing ig because the tree flickers but nothing else |
Beta Was this translation helpful? Give feedback.
-
2024-07-02_18-00-23.mp4theres also this weird problem where the tree flickers for some while, configlocal autocmd = _G.autocmd
return {
{
"nvim-tree/nvim-tree.lua",
cmd = { "NvimTreeFindFileToggle", "NvimTreeOpen", "NvimTreeClose", "NvimTreeFindFile" },
version = "*",
lazy = false,
event = { "LazyFile" },
dependencies = {
{ "b0o/nvim-tree-preview.lua", lazy = true },
},
keys = {
{ "<C-n>", "<cmd>NvimTreeFindFileToggle<cr>", desc = "NvimTree" },
},
config = function()
local nvimtree_status_ok, nvimtree = pcall(require, "nvim-tree")
if not nvimtree_status_ok then
print("NvimTree not found!")
end
local icons_ok, icons = pcall(require, "NeutronVim.core.icons")
if not icons_ok then
print("Unable to import icons!")
end
vim.opt.termguicolors = true
local HEIGHT_RATIO = 0.8
local WIDTH_RATIO = 0.8
nvimtree.setup({
filters = { custom = { "*.tmp", "*.git" } },
disable_netrw = true,
hijack_netrw = true,
respect_buf_cwd = true,
update_focused_file = {
enable = true,
update_cwd = true,
},
hijack_cursor = true,
update_cwd = true,
view = {
number = true,
relativenumber = true,
float = {
enable = true,
quit_on_focus_loss = true,
open_win_config = function()
local screen_w = vim.opt.columns:get()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local window_w = screen_w * WIDTH_RATIO
local window_h = screen_h * HEIGHT_RATIO
local window_w_int = math.floor(window_w)
local window_h_int = math.floor(window_h)
local center_x = (screen_w - window_w) / 2
local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get()
return {
border = "rounded",
relative = "editor",
row = center_y,
col = center_x,
width = window_w_int,
height = window_h_int,
}
end,
},
width = function()
return math.floor(vim.opt.columns:get() * WIDTH_RATIO)
end,
},
renderer = {
indent_markers = {
enable = true,
inline_arrows = true,
icons = {
corner = icons.ui.Corner,
edge = icons.ui.Edge,
item = icons.ui.Item,
bottom = icons.ui.Bottom,
none = icons.ui.None,
},
},
highlight_modified = "all",
icons = {
glyphs = {
folder = {
arrow_closed = icons.ui.ArrowClosed,
arrow_open = icons.ui.ArrowOpen,
},
},
webdev_colors = true,
git_placement = "before",
modified_placement = "after",
padding = " ",
symlink_arrow = " ➛ ",
show = {
file = true,
folder = true,
folder_arrow = true,
git = true,
modified = true,
diagnostics = true,
bookmarks = true,
},
},
},
modified = {
enable = true,
show_on_dirs = true,
},
diagnostics = {
enable = true,
show_on_open_dirs = true,
icons = {
hint = icons.diagnostics.Hint,
info = icons.diagnostics.Info,
warning = icons.diagnostics.Warning,
error = icons.diagnostics.Error,
},
},
git = {
enable = true,
ignore = false,
timeout = 500,
},
on_attach = function(bufnr)
local api = require("nvim-tree.api")
local preview = require("nvim-tree-preview")
api.events.subscribe(api.events.Event.FileCreated, function(file)
vim.cmd("edit " .. file.fname)
end)
local function opts(desc)
return { desc = "NvimTree " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- Default Mappings
api.config.mappings.default_on_attach(bufnr)
-- Nvim-Tree Preview Plugin Mappings
vim.keymap.set("n", "P", preview.watch, opts("Preview (Watch)"))
vim.keymap.set("n", "<Esc>", preview.unwatch, opts("Close Preview/Unwatch"))
vim.keymap.set("n", "q", function()
if preview.is_watching() or preview.is_open() then
preview.unwatch()
else
api.tree.close()
end
end, opts("Close Preview/Unwatch"))
vim.keymap.set("n", "<Tab>", function()
local ok, node = pcall(api.tree.get_node_under_cursor)
if ok and node then
if node.type == "directory" then
api.node.open.edit()
else
preview.node(node, { toggle_focus = true })
end
end
end, opts("Preview"))
vim.keymap.set(
"n",
"<leader>f",
"<cmd>lua require('NeutronVim.core.utils').launch_find_files()<cr>",
opts("Find Files")
)
vim.keymap.set(
"n",
"<leader>g",
"<cmd>lua require('NeutronVim.core.utils').launch_live_grep()<cr>",
opts("Live Grep")
)
vim.keymap.set(
"n",
";g",
"<cmd>lua require('NeutronVim.core.utils').stage_file()<cr>",
opts("Stage/Unstage File")
)
vim.keymap.set("n", "<C-c>", function()
local global_cwd = vim.fn.getcwd(-1, -1)
api.tree.change_root(global_cwd)
end, opts("Change Root To Global CWD"))
vim.keymap.set("n", "T", function(node)
api.node.open.tab(node)
vim.cmd.tabprev()
end, opts("Open Tab Silent"))
end,
})
autocmd("VimResized", "*", function()
if require("nvim-tree.view").is_visible() then
require("nvim-tree.view").close()
require("nvim-tree").open()
end
end, "NvimTreeResize")
end,
},
} |
Beta Was this translation helpful? Give feedback.
-
i also cannot cmd = { "NvimTreeFindFileToggle", "NvimTreeOpen", "NvimTreeClose", "NvimTreeFindFile" }, are not added to my |
Beta Was this translation helpful? Give feedback.
-
I've tried to reproduce with your on_attach with a minimal config however was not able to. I suspect there are other plugins or configuration that is interfering with Please raise a bug report with a minimal configuration and instructions on replication. Tip: use the |
Beta Was this translation helpful? Give feedback.
-
That can happen for large directories, especially when they are in a git repo. Please enable performance logging so that we may see where the bottleneck lies. Once again, a bug report would be most useful. |
Beta Was this translation helpful? Give feedback.
-
It looks like you bound neutron vim to When I bound it to the function it works nicely: |
Beta Was this translation helpful? Give feedback.
-
Sorry, can't help you with lazy. I don't recommend it: https://github.com/nvim-tree/nvim-tree.lua/wiki/Installation#lazy-loading |
Beta Was this translation helpful? Give feedback.
-
so im trying to setup the
on_attach
function, but im going through some difficulties:but theres one thing which is bothering me, if i enable the 2 keybindings:
c-v
,c-x
: C-x works without any hassle but c-v causes a problem: paste:so its trying to paste stuff, also if i enable those 3 keybindings (c-t and c-x works without setting it too, and c-v isnt working in both cases) c-x is conflicting with the rename function, when i press
r
(after doing c-x once), the rename dialog opens, but if i close dialog byesc
=> i didnt change name, i get this notification:also i wanted to say that if i press c-x on the currently opened file in nvim-tree, it just closes it, i want to open it in a split
Beta Was this translation helpful? Give feedback.
All reactions