-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathneotree.lua
More file actions
172 lines (167 loc) · 6.1 KB
/
Copy pathneotree.lua
File metadata and controls
172 lines (167 loc) · 6.1 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
local function close_vim_fugitive_window()
for _, window in ipairs(vim.api.nvim_list_wins()) do
local buffer = vim.api.nvim_win_get_buf(window)
local buffer_name = vim.api.nvim_buf_get_name(buffer)
if buffer_name:find("fugitive:", 1, true) then
vim.api.nvim_win_close(window, false)
end
end
end
local function is_windows()
local result = (vim.fn.has("win32") == 1) or (vim.fn.has("win64") == 1)
return result
end
return {
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
lazy = false,
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"MunifTanjim/nui.nvim",
"tpope/vim-fugitive",
"famiu/bufdelete.nvim"
},
cmd = {
"Neotree"
},
keys = {
{ "<C-b>", "<CMD>Neotree source=filesystem action=focus position=left<CR>", mode = { "n", "v", "i" } },
{ "<C-g>", "<CMD>Neotree source=git_status action=focus position=left<CR>", mode = { "n", "v", "i" } },
},
main = "neo-tree",
init = function()
vim.api.nvim_create_autocmd('FileType', {
pattern = { "gitcommit" },
callback = function(opts)
vim.keymap.set("n", "<C-c><C-c>", ":w<CR>:Bd<CR>", { buffer = opts.buf })
vim.keymap.set("i", "<C-c><C-c>", "<C-\\><C-n>:w<CR>:Bd<CR>", { buffer = opts.buf })
end,
group = vim.api.nvim_create_augroup("git-commit-keymap", { clear = true })
})
end,
opts = {
use_libuv_file_watcher = (not is_windows()),
open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" },
git_status_async = false,
close_if_last_window = true,
popup_border_style = "single",
enable_diagnostics = false,
enable_git_status = false,
window = {
mappings = {
["c"] = nil,
}
},
git_status = {
window = {
width = 30,
mappings = {
["<CR>"] = "preview_diff",
["D"] = "open_diff",
["o"] = "open_custom",
["<tab>"] = "preview_file",
["<C-g>"] = "close_window",
["<C-b>"] = "switch_to_filesystem",
["S"] = "git_add_all",
["U"] = "git_unstage_all",
["s"] = "git_add_file",
["u"] = "git_unstage_file",
["X"] = "git_revert_file",
["cc"] = { "git_commit_custom", config = { amend = false } },
["ca"] = { "git_commit_custom", config = { amend = true } },
["c"] = "noop",
["A"] = "noop",
}
},
},
filesystem = {
window = {
width = 30,
mappings = {
["<F5>"] = "refresh",
["<F2>"] = "rename",
["D"] = "open_diff",
["<C-b>"] = "close_window",
},
},
filtered_items = {
visible = false,
hide_dotfiles = false,
hide_gitignored = false,
hide_by_name = {
"node_modules",
},
never_show = {
"__pycache__",
".DS_Store",
"thumbs.db",
".git",
},
},
follow_current_file = { enabled = true },
},
default_component_configs = {
icon = {
folder_empty = ""
},
git_status = {
symbols = {
-- Change type
added = " ",
modified = " ",
deleted = " ",
renamed = "", -- this can only be used in the git_status source
-- Status type
untracked = "",
ignored = "",
unstaged = "",
staged = "",
conflict = "",
}
}
},
commands = {
preview_diff = function(state)
close_vim_fugitive_window()
require("neo-tree.sources.filesystem.commands").open(state)
vim.cmd [[ Gvdiffsplit! | wincmd = | Neotree git_status reveal ]]
end,
open_diff = function(state)
close_vim_fugitive_window()
require("neo-tree.sources.filesystem.commands").open(state)
vim.cmd [[ Gvdiffsplit! | wincmd = | wincmd h ]]
end,
open_custom = function(state)
close_vim_fugitive_window()
require("neo-tree.sources.filesystem.commands").open(state)
end,
preview_file = function(state)
close_vim_fugitive_window()
require("neo-tree.sources.filesystem.commands").open(state)
vim.cmd [[ Neotree git_status reveal ]]
end,
git_unstage_all = function()
local events = require("neo-tree.events")
local command = { "git", "reset" }
vim.fn.system(command)
events.fire_event(events.GIT_EVENT)
end,
git_commit_custom = function(state)
if state.config.amend then
vim.cmd [[ wincmd l | Git commit --amend | wincmd j | wincmd c ]]
else
print("Commiting")
vim.cmd [[ wincmd l | Git commit | wincmd k | wincmd c ]]
end
vim.schedule(function()
local events = require("neo-tree.events")
events.fire_event(events.GIT_EVENT)
end)
end,
switch_to_filesystem = function()
vim.cmd [[ Neotree filesystem reveal ]]
end
}
}
}