nvim tree auto open

主要在 ~/.config/nvim/lua/plugins/nvim-tree.lua 添加配置

1
2
3
4
--auto open from terminal
if vim.fn.argc(-1) == 0 then
    vim.cmd('NvimTreeOpen')
end
 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
-- 查看默认配置
-- :help vim-tree-mappings-default
local function my_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)

    -- your removals and mappings go here
    -- copy default mappings here from defaults in next section
    vim.keymap.set('n', '<C-]>', api.tree.change_root_to_node, opts('CD'))
    vim.keymap.set('n', '<C-e>', api.node.open.replace_tree_buffer, opts('Open: In Place'))
    ---
    -- OR use all default mappings
    api.config.mappings.default_on_attach(bufnr)

    -- remove a default
    vim.keymap.del('n', '<C-]>', { buffer = bufnr })

    -- override a default
    vim.keymap.set('n', 'r', api.tree.reload, opts('Refresh'))
    vim.keymap.set('n', 'u', api.tree.change_root_to_parent, opts('Up'))
    vim.keymap.set('n', 'x', api.node.navigate.parent_close, opts('Close Directory'))
    vim.keymap.set('n', '<CR>', api.node.open.no_window_picker, opts('Open: No Window Picker'))
    vim.keymap.set('n', 'o', api.node.open.no_window_picker, opts('Open: No Window Picker'))
    vim.keymap.set('n', 'p', api.node.open.preview, opts('Open  Preview'))

    -- add your mappings
    vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
    ---
end

return {
    "nvim-tree/nvim-tree.lua",
    -- version = "*",
    -- version = "v10.16.0",
    branch = "master",
    -- commit= "f1b3e6a7eb92da492bd693257367d9256839ed3d",
    commit= "fbee8a69a46f558d29ab84e96301425b0501c668",    -- ok:
    -- commit= "d9cb432d2c8d8fa9267ddbd7535d76fe4df89360", --broken
    -- commit= "e9ac136a3ab996aa8e4253253521dcf2cb66b81b", -- broken
    dependencies = { "nvim-tree/nvim-web-devicons" },
    event = "VeryLazy",
    -- hijack_directories = {
    --     enable = true,
    --     auto_open = false,
    --     },
    config = function()
        require("nvim-tree").setup {
            view = {
                width = 35, -- pt
                side = "left",
                -- bindings = {
                --     { key = {"<CR>", "o" }, action = "edit", mode = "n"},
                --     { key = "p", action = "print_path", action_cb = print_node_path },
                -- }
            },
            -- renderer = {
            --     group_empty = true,
            -- },
            -- filters = {
            --     dotfiles = true,
            -- },
            ui = {
                confirm = {
                    remove = true,
                    trash = true,
                },
            },
            actions = {
                open_file = {
                    resize_window = false,
                },
            },
            git = {
                enable = true,
                ignore = false,
            },
            on_attach = my_on_attach,
        }
        --auto open from terminal
        if vim.fn.argc(-1) == 0 then
            vim.cmd('NvimTreeOpen')
        end
    end
}
william 支付宝支付宝
william 微信微信
0%