summaryrefslogtreecommitdiff
path: root/config/nvim/lua/plugins/tree.lua
blob: 18f217bfe84710df3944ad94d604740f6ca987ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
local HEIGHT_RATIO = 0.8
local WIDTH_RATIO = 0.5
return {
	"nvim-tree/nvim-tree.lua",
	dependencies = {
		"nvim-tree/nvim-web-devicons",
	},
	opts = {
		disable_netrw = false,
		hijack_netrw = true,
		sort = {
			sorter = "case_sensitive",
		},
		git = {
			enable = true,
			ignore = false,
		},
		renderer = {
			group_empty = true,
			highlight_git = true,
			icons = {
				show = {
					git = true,
				},
			},
		},
		filters = {
			dotfiles = false,
		},
		update_focused_file = {
			enable = true,
		},
		on_attach = function(bufnr)
			local api = require("nvim-tree.api")
			api.config.mappings.default_on_attach(bufnr)
			vim.api.nvim_set_hl(0, "NvimTreeNormal", { bg = vim.o.background == "dark" and "#1c1c1f" or "#e7e7e7" })
		end,
		view = {
			float = {
				enable = 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()
					local border_bg = vim.o.background == "dark" and "#1c1c1f" or "#e7e7e7"
					local border_fg = vim.o.background == "dark" and "#333333" or "#999999"
					-- Force highlight for border and nvim-tree background
					vim.api.nvim_set_hl(0, "FloatBorder", { fg = border_fg, bg = border_bg })
					vim.api.nvim_set_hl(0, "NvimTreeFloatBorder", { fg = border_fg, bg = border_bg })
					vim.api.nvim_set_hl(0, "NvimTreeNormal", { bg = border_bg })
					vim.api.nvim_set_hl(0, "NormalFloat", { bg = border_bg })
					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,
		},
	},
	keys = {
		{
			"<C-c>",
			function()
				local api = require("nvim-tree.api")
				local global_cwd = vim.fn.getcwd(-1, -1)
				api.tree.change_root(global_cwd)
			end,
			desc = "Change tree root to CWD",
		},
		{
			"<F3>",
			"<cmd>NvimTreeToggle<CR>",
			desc = "Toggle file tree",
		},
	},
}