95 lines
3.1 KiB
Lua
95 lines
3.1 KiB
Lua
local ok, tree = pcall(require, 'nvim-tree')
|
|
if not ok then
|
|
vim.notify('nvim-tree load error')
|
|
return
|
|
end
|
|
|
|
vim.g.loaded = 1
|
|
vim.g.loaded_netrwPlugin = 1
|
|
|
|
local function mapping_on_attach(bufnr)
|
|
local api = require('nvim-tree.api')
|
|
|
|
local function opts(desc)
|
|
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
|
|
end
|
|
|
|
api.config.mappings.default_on_attach(bufnr)
|
|
-- NOTE: default <C-v> open new tab vertical
|
|
-- NOTE: default <C-x> open new tab horizental
|
|
-- vim.keymap.set('n', '<C-v>', api.node.open.vertical, opts('Open: Vertical Split'))
|
|
-- vim.keymap.set('n', '<C-x>', api.node.open.horizontal, opts('Open: Horizontal Split'))
|
|
vim.keymap.del('n', '<C-v>', { buffer = bufnr })
|
|
vim.keymap.del('n', '<C-x>', { buffer = bufnr })
|
|
vim.keymap.del('n', 's', { buffer = bufnr })
|
|
vim.keymap.del('n', '-', { buffer = bufnr })
|
|
|
|
-- set new mapping
|
|
vim.keymap.set('n', 'v', api.node.open.vertical, opts('Open: Vertical Split'))
|
|
vim.keymap.set('n', 's', api.node.open.horizontal, opts('Open: Horizontal Split'))
|
|
vim.keymap.set('n', 'u', api.tree.change_root_to_parent, opts('Up'))
|
|
end
|
|
|
|
tree.setup({
|
|
sort_by = "case_sensitive",
|
|
|
|
view = {
|
|
adaptive_size = true,
|
|
float = {
|
|
enable = true,
|
|
},
|
|
-- Deprecated mapping
|
|
-- mappings = {
|
|
-- list = {
|
|
-- { key = "u", action = "dir_up" },
|
|
-- { key = "v", action = "vsplit" },
|
|
-- { key = "s", action = "split" },
|
|
-- },
|
|
-- },
|
|
},
|
|
|
|
on_attach = mapping_on_attach,
|
|
|
|
renderer = {
|
|
group_empty = true,
|
|
},
|
|
|
|
filters = {
|
|
dotfiles = true,
|
|
custom = { "*.o", "*.so", "*.dll", "*.exe", "*.dat", "*.class" },
|
|
},
|
|
|
|
git = {
|
|
enable = true,
|
|
show_on_dirs = true,
|
|
show_on_open_dirs = true,
|
|
disable_for_dirs = {},
|
|
timeout = 4000,
|
|
cygwin_support = false,
|
|
},
|
|
})
|
|
|
|
vim.api.nvim_set_keymap('n', '<leader>t', ':NvimTreeToggle<CR>', {noremap = true, silent = true})
|
|
vim.api.nvim_set_keymap('n', '<leader>l', ':NvimTreeFindFile<CR>', {noremap = true, silent = true})
|
|
|
|
vim.cmd([[autocmd StdinReadPre * let s:std_in=1]])
|
|
-- vim.cmd([[autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NvimTreeOpen' argv()[0] | wincmd p | ene | endif]])
|
|
|
|
-- try to close nvim when only NvimTree is open
|
|
-- vim.cmd([[autocmd BufEnter * if (winnr("$") == 1 && bufname('%') =~ 'NvimTree_\d') | q | endif]])
|
|
-- 替换上面这行 vimscript
|
|
vim.api.nvim_create_autocmd("BufEnter", {
|
|
-- pattern = "NvimTree",
|
|
callback = function()
|
|
if vim.fn.winnr("$") == 1 and string.match(vim.fn.bufname("%"), "NvimTree_%d") ~= nil then
|
|
-- vim.api.quit()
|
|
vim.cmd("q")
|
|
end
|
|
end,
|
|
})
|
|
|
|
-- If another buffer tries to replace NvimTree, put it in the other window, and bring back NvimTree.
|
|
vim.cmd([[autocmd BufEnter * if bufname('#') =~ 'NvimTree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 | let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif]])
|
|
|
|
vim.cmd([[autocmd FileType NvimTree set laststatus=0 showtabline=0 | autocmd BufLeave <buffer> set laststatus=2 showtabline=2]])
|