Skip to content

Commit

Permalink
Update .config/nvim/lua/plugins/nvim-tree.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyuga-Tsukui committed Nov 28, 2024
1 parent bcbf0a6 commit 76d3e3c
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions dot_config/nvim/lua/plugins/nvim-tree.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
return {
"nvim-tree/nvim-tree.lua",
dependencies = "nvim-tree/nvim-web-devicons",
-- event = "VeryLazy",
config = function()
require("nvim-tree").setup({})
vim.keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>")
-- vim.keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>")

-- リサイズ関数を定義
local function resize_nvim_tree()
local max_width = 0
for _, line in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
local line_width = vim.fn.strdisplaywidth(line)
if line_width > max_width then
max_width = line_width
end
end
vim.api.nvim_win_set_width(0, max_width + 10)
end

-- NvimTreeが開かれているかチェック
local function is_nvim_tree()
local bufname = vim.api.nvim_buf_get_name(0)
return bufname:match("NvimTree_") ~= nil
end

-- NvimTreeToggleの後にリサイズ処理を追加
vim.keymap.set("n", "<leader>e", function()
vim.cmd("NvimTreeToggle")
-- 遅延してリサイズを実行
vim.defer_fn(function()
if is_nvim_tree() then
resize_nvim_tree()
end
end, 50) -- 50ms 待機(NvimTreeが開かれるのを待つ)
end, { desc = "Toggle NvimTree and resize" })
end,
}

0 comments on commit 76d3e3c

Please sign in to comment.