Edit: Alex: added syntax highlighting
\nI'm a newbie with neovim plugin sorry if I don't understand everything at the first time
\nThank you for your help
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Thanks for raising. View is not API hence it will change.
You can use the API to achieve what you need. See :help nvim-tree-api
view.is_visible -> api.tree.is_visible\nview.get_winnr -> api.tree.winid\nview.resize -> api.tree.resize, passing params for width\nPlease advise whether you're successful.
","upvoteCount":1,"url":"https://github.com/nvim-tree/nvim-tree.lua/discussions/3159#discussioncomment-13534841"}}}-
|
Hey, Since the last update, I cannot use this nvim plugin properly. I saw that nvim-tree.view has been moved but with that config I don't really see what should I do and how should I initialize my local view variable return {
"nvim-tree/nvim-tree.lua",
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
local function my_on_attach(bufnr)
local api = require("nvim-tree.api")
local view = require("nvim-tree.view")
local function opts(desc)
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
vim.keymap.set("n", "<C-n>", api.fs.create, opts("Create"))
vim.keymap.set("n", "<C-CR>", api.tree.change_root_to_node, opts("Change Root to Node"))
vim.keymap.set("n", "<CR>", api.node.open.edit, opts("Open"))
vim.keymap.set("n", "o", api.node.open.edit, opts("Open"))
vim.keymap.set("n", "<2-LeftMouse>", api.node.open.edit, opts("Open with mouse"))
vim.keymap.set("n", "<C-Right>", function()
if view.is_visible() then
local width = view.View.width
view.View.width = width + 5
view.resize()
end
end, opts("Increase Width"))
vim.keymap.set("n", "<C-Left>", function()
if view.is_visible() then
local width = view.View.width
view.View.width = math.max(width - 5, 10)
view.resize()
end
end, opts("Decrease Width"))
end
require("nvim-tree").setup({
on_attach = my_on_attach, -- Attache les remaps personnalisés
view = {
side = "left", -- Affiche l'arbre sur le côté gauche
width = 30, -- Largeur de la fenêtre
},
renderer = {
group_empty = true, -- Groupe les dossiers vides
},
filters = {
dotfiles = false, -- Affiche les fichiers cachés (.git, etc.)
},
git = {
enable = true, -- Affiche l'état Git
},
})
vim.keymap.set("n", "<leader>b", "<cmd>NvimTreeToggle<CR>", { desc = "Toggle File Explorer" })
local function toggle_focus()
local view = require("nvim-tree.view")
if view.is_visible() then
if vim.api.nvim_get_current_win() == view.get_winnr() then
-- Si `nvim-tree` est actif, passe à la fenêtre de code
vim.cmd("wincmd l")
else
-- Sinon, passe à `nvim-tree`
vim.cmd("wincmd p")
end
end
end
vim.keymap.set("n", "<leader>c", toggle_focus, { desc = "Switch entre NvimTree et code" })
end,
}Edit: Alex: added syntax highlighting I'm a newbie with neovim plugin sorry if I don't understand everything at the first time Thank you for your help |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for raising. You can use the API to achieve what you need. See Please advise whether you're successful. |
Beta Was this translation helpful? Give feedback.
Thanks for raising.
Viewis not API hence it will change.You can use the API to achieve what you need. See
:help nvim-tree-apiPlease advise whether you're successful.