feat: make nvimtree lazy
This commit is contained in:
parent
39142a5231
commit
39ddcf0b7d
2 changed files with 43 additions and 1 deletions
|
|
@ -10,3 +10,45 @@
|
||||||
-- vim.cmd("set norelativenumber")
|
-- vim.cmd("set norelativenumber")
|
||||||
-- end,
|
-- end,
|
||||||
-- })
|
-- })
|
||||||
|
|
||||||
|
-- nvim-tree is also there in modified buffers so this function filter it out
|
||||||
|
local modifiedBufs = function(bufs)
|
||||||
|
local t = 0
|
||||||
|
for k, v in pairs(bufs) do
|
||||||
|
if v.name:match("NvimTree_") == nil then
|
||||||
|
t = t + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("BufEnter", {
|
||||||
|
nested = true,
|
||||||
|
callback = function()
|
||||||
|
if #vim.api.nvim_list_wins() == 1 and
|
||||||
|
vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil and
|
||||||
|
modifiedBufs(vim.fn.getbufinfo({ bufmodified = 1 })) == 0 then
|
||||||
|
vim.cmd "quit"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
local function open_nvim_tree(data)
|
||||||
|
|
||||||
|
-- buffer is a directory
|
||||||
|
local directory = vim.fn.isdirectory(data.file) == 1
|
||||||
|
|
||||||
|
if not directory then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- change to the directory
|
||||||
|
if directory then
|
||||||
|
vim.cmd.cd(data.file)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- open the tree
|
||||||
|
require("nvim-tree.api").tree.open()
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"nvim-tree/nvim-tree.lua",
|
"nvim-tree/nvim-tree.lua",
|
||||||
|
lazy = true,
|
||||||
opts = {
|
opts = {
|
||||||
on_attach = function(bufnr)
|
on_attach = function(bufnr)
|
||||||
local api = require("nvim-tree.api")
|
local api = require("nvim-tree.api")
|
||||||
|
|
@ -61,7 +62,6 @@ return {
|
||||||
vim.keymap.set("n", "<2-RightMouse>", api.tree.change_root_to_node, opts("CD"))
|
vim.keymap.set("n", "<2-RightMouse>", api.tree.change_root_to_node, opts("CD"))
|
||||||
end,
|
end,
|
||||||
respect_buf_cwd = true,
|
respect_buf_cwd = true,
|
||||||
open_on_setup = true,
|
|
||||||
view = {
|
view = {
|
||||||
centralize_selection = false,
|
centralize_selection = false,
|
||||||
side = "right",
|
side = "right",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue