feat(nvim.plugins.neotree): upgrade neotree to 2.X and prioritize it over nvim-tree

This commit is contained in:
Bruno Carlin 2022-06-15 11:24:15 +02:00
parent ac9e793610
commit 47ae298996
3 changed files with 125 additions and 235 deletions

View file

@ -8,7 +8,6 @@ require "plugins.indent"
require "plugins.lsp_signature"
require "plugins.lualine"
require "plugins.neogit"
require "plugins.neotree"
require "plugins.nvimgo"
require "plugins.nvimgoc"
require "plugins.nvimtree"
@ -17,3 +16,4 @@ require "plugins.snippy"
require "plugins.telescope"
require "plugins.treesitter"
require "plugins.treesitter_textobject"
require "plugins.neotree"

View file

@ -22,7 +22,7 @@ return require('packer').startup(function(use)
}
use {
"nvim-neo-tree/neo-tree.nvim",
branch = "v1.x",
branch = "v2.x",
requires = {
"nvim-lua/plenary.nvim",
"kyazdani42/nvim-web-devicons", -- not strictly required, but recommended

View file

@ -1,295 +1,185 @@
-- See ":help neo-tree-highlights" for a list of available highlight groups
vim.cmd [[
highlight clear NeoTreeDirectoryName
highlight! link NeoTreeDirectoryName Directory
highlight! link NeoTreeDirectoryIcon NeoTreeDirectoryName
"highlight! NeoTreeIndentMarker ctermfg=11
highlight! NeoTreeDimText ctermfg=11
"highlight clear NeoTreeDirectoryName
"highlight! link NeoTreeDirectoryName Directory
"highlight! link NeoTreeDirectoryIcon NeoTreeDirectoryName
highlight! NeoTreeIndentMarker ctermfg=11
"highlight! NeoTreeDimText ctermfg=11
]]
local config = {
default_source = "filesystem",
close_if_last_window = true, -- Close Neo-tree if it is the last window left in the tab
-- popup_border_style is for input and confirmation dialogs.
-- Configurtaion of floating window is done in the individual source sections.
-- "NC" is a special style that works well with NormalNC set
popup_border_style = "NC", -- "double", "none", "rounded", "shadow", "single" or "solid"
use_popups_for_input = true, -- If false, inputs will use vim.ui.input() instead of custom floats.
close_floats_on_escape_key = true,
close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab
popup_border_style = "rounded",
enable_git_status = true,
enable_diagnostics = true,
open_files_in_last_window = true, -- false = open files in top left window
log_level = "debug", -- "trace", "debug", "info", "warn", "error", "fatal"
log_to_file = true, -- true, false, "/path/to/file.log", use :NeoTreeLogs to show the file
--
--event_handlers = {
-- {
-- event = "before_render",
-- handler = function (state)
-- -- add something to the state that can be used by custom components
-- end
-- },
-- {
-- event = "file_opened",
-- handler = function(file_path)
-- --auto close
-- require("neo-tree").close_all()
-- end
-- },
-- {
-- event = "file_opened",
-- handler = function(file_path)
-- --clear search after opening a file
-- require("neo-tree.sources.filesystem").reset_search()
-- end
-- },
-- {
-- event = "file_renamed",
-- handler = function(args)
-- -- fix references to file
-- print(args.source, " renamed to ", args.destination)
-- end
-- },
-- {
-- event = "file_moved",
-- handler = function(args)
-- -- fix references to file
-- print(args.source, " moved to ", args.destination)
-- end
-- },
--},
default_component_configs = {
container = {
enable_character_fade = true
},
indent = {
indent_size = 2,
padding = 1,
padding = 1, -- extra padding on left hand side
-- indent guides
with_markers = true,
indent_marker = "",
last_indent_marker = "",
highlight = "NeoTreeIndentMarker",
-- expander config, needed for nesting files
with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders
expander_collapsed = "",
expander_expanded = "",
expander_highlight = "NeoTreeExpander",
},
icon = {
folder_closed = "",
folder_open = "",
folder_closed = "",
folder_open = "",
folder_empty = "",
-- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there
-- then these will never be used.
default = "*",
highlight = "NeoTreeFileIcon"
},
modified = {
symbol = "[+]",
highlight = "NeoTreeModified",
},
name = {
trailing_slash = true,
trailing_slash = false,
use_git_status_colors = true,
highlight = "NeoTreeFileName",
},
git_status = {
highlight = "NeoTreeDimText",
symbols = {
-- Change type
added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name
modified = "", -- or "", but this is redundant info if you use git_status_colors on the name
deleted = "",-- this can only be used in the git_status source
renamed = "",-- this can only be used in the git_status source
-- Status type
untracked = "",
ignored = "",
unstaged = "",
staged = "",
conflict = "",
}
},
},
window = {
position = "left",
width = 40,
mapping_options = {
noremap = true,
nowait = true,
},
mappings = {
["<space>"] = {
"toggle_node",
nowait = false, -- disable `nowait` if you have existing combos starting with this char that you want to use
},
["<2-LeftMouse>"] = "open",
["<cr>"] = "open",
["S"] = "open_split",
["s"] = "open_vsplit",
-- ["S"] = "split_with_window_picker",
-- ["s"] = "vsplit_with_window_picker",
["t"] = "open_tabnew",
["w"] = "open_with_window_picker",
["C"] = "close_node",
["a"] = {
"add",
-- some commands may take optional config options, see `:h neo-tree-mappings` for details
config = {
show_path = "none" -- "none", "relative", "absolute"
}
},
["A"] = "add_directory", -- also accepts the config.show_path option.
["d"] = "delete",
["r"] = "rename",
["y"] = "copy_to_clipboard",
["x"] = "cut_to_clipboard",
["p"] = "paste_from_clipboard",
["c"] = "copy", -- takes text input for destination
["m"] = "move", -- takes text input for destination
["q"] = "close_window",
["R"] = "refresh",
["?"] = "show_help",
}
},
nesting_rules = {},
filesystem = {
filtered_items = {
visible = false, -- when true, they will just be displayed differently than normal items
hide_dotfiles = false,
hide_gitignored = false,
hide_hidden = true, -- only works on Windows for hidden files/directories
hide_by_name = {
".git",
},
hide_by_pattern = { -- uses glob style patterns
--"*.meta"
},
never_show = { -- remains hidden even if visible is toggled to true
--".DS_Store",
--"thumbs.db"
},
},
follow_current_file = false, -- This will find and focus the file in the active buffer every
-- time the current file is changed while the tree is open.
group_empty_dirs = false, -- when true, empty folders will be grouped together
hijack_netrw_behavior = "open_default", -- netrw disabled, opening a directory opens neo-tree
-- in whatever position is specified in window.position
-- "open_split", -- netrw disabled, opening a directory opens within the
-- "open_current", -- netrw disabled, opening a directory opens within the
-- window like netrw would, regardless of window.position
-- "disabled", -- netrw left alone, neo-tree does not handle opening dirs
follow_current_file = false, -- This will find and focus the file in the active buffer every time
-- the current file is changed while the tree is open.
use_libuv_file_watcher = false, -- This will use the OS level file watchers to detect changes
-- instead of relying on nvim autocmd events.
window = { -- see https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup for
-- possible options. These can also be functions that return these options.
position = "left", -- left, right, float, split
width = 40, -- applies to left and right positions
popup = { -- settings that apply to float position only
size = {
height = "80%",
width = "50%",
},
position = "50%", -- 50% means center it
-- you can also specify border here, if you want a different setting from
-- the global popup_border_style.
},
-- Mappings for tree window. See `:h nep-tree-mappings` for a list of built-in commands.
-- You can also create your own commands by providing a function instead of a string.
window = {
mappings = {
["<2-LeftMouse>"] = "open",
["<cr>"] = "open",
["S"] = "open_split",
["s"] = "open_vsplit",
["C"] = "close_node",
["z"] = "close_all_nodes",
["<bs>"] = "navigate_up",
["."] = "set_root",
["H"] = "toggle_hidden",
["I"] = "toggle_gitignore",
["R"] = "refresh",
["/"] = "fuzzy_finder",
--["/"] = "filter_as_you_type", -- this was the default until v1.28
["f"] = "filter_on_submit",
["<C-x>"] = "clear_filter",
["a"] = "add",
["d"] = "delete",
["r"] = "rename",
["c"] = "copy_to_clipboard",
["x"] = "cut_to_clipboard",
["p"] = "paste_from_clipboard",
["y"] = "copy", -- takes text input for destination
["m"] = "move", -- takes text input for destination
["q"] = "close_window",
},
},
--find_command = "fd",
--find_args = { -- you can specify extra args to pass to the find command.
-- "--exclude", ".git",
-- "--exclude", "node_modules"
--},
---- or use a function instead of list of strings
--find_args = function(cmd, path, search_term, args)
-- if cmd ~= "fd" then
-- return args
-- end
-- --maybe you want to force the filter to always include hidden files:
-- table.insert(args, "--hidden")
-- -- but no one ever wants to see .git files
-- table.insert(args, "--exclude")
-- table.insert(args, ".git")
-- -- or node_modules
-- table.insert(args, "--exclude")
-- table.insert(args, "node_modules")
-- --here is where it pays to use the function, you can exclude more for
-- --short search terms, or vary based on the directory
-- if string.len(search_term) < 4 and path == "/home/cseickel" then
-- table.insert(args, "--exclude")
-- table.insert(args, "Library")
-- end
-- return args
--end,
search_limit = 50, -- max number of search results when using filters
filters = {
show_hidden = false,
respect_gitignore = false,
},
bind_to_cwd = false, -- true creates a 2-way binding between vim's cwd and neo-tree's root
-- The renderer section provides the renderers that will be used to render the tree.
-- The first level is the node type.
-- For each node type, you can specify a list of components to render.
-- Components are rendered in the order they are specified.
-- The first field in each component is the name of the function to call.
-- The rest of the fields are passed to the function as the "config" argument.
renderers = {
directory = {
{ "clipboard" },
{ "indent" },
{ "icon" },
{ "current_filter" },
{ "name" },
-- {
-- "symlink_target",
-- highlight = "NeoTreeSymbolicLinkTarget",
-- },
{ "diagnostics" },
{ "git_status" },
},
file = {
{ "clipboard" },
{ "indent" },
{ "icon" },
{
"name",
use_git_status_colors = true,
},
-- {
-- "symlink_target",
-- highlight = "NeoTreeSymbolicLinkTarget",
-- },
{ "diagnostics" },
{ "git_status" },
},
},
["<c-x>"] = "clear_filter",
["[g"] = "prev_git_modified",
["]g"] = "next_git_modified",
}
}
},
buffers = {
follow_current_file = true, -- This will find and focus the file in the active buffer every
-- time the current file is changed while the tree is open.
group_empty_dirs = true, -- when true, empty folders will be grouped together
show_unloaded = true,
window = {
position = "left",
width = 40,
mappings = {
["<2-LeftMouse>"] = "open",
["<cr>"] = "open",
["S"] = "open_split",
["s"] = "open_vsplit",
["bd"] = "buffer_delete",
["<bs>"] = "navigate_up",
["."] = "set_root",
["R"] = "refresh",
["a"] = "add",
["d"] = "delete",
["r"] = "rename",
["c"] = "copy_to_clipboard",
["x"] = "cut_to_clipboard",
["p"] = "paste_from_clipboard",
["bd"] = "buffer_delete",
},
},
bind_to_cwd = true,
renderers = {
directory = {
{ "indent" },
{ "icon" },
{ "name" },
{ "diagnostics", errors_only = true },
{ "clipboard" },
},
file = {
{ "indent" },
{ "icon" },
{ "name" },
{ "bufnr" },
{ "diagnostics" },
{ "git_status" },
{ "clipboard" },
},
}
},
},
git_status = {
window = {
position = "left",
width = 40,
position = "float",
mappings = {
["<2-LeftMouse>"] = "open",
["<cr>"] = "open",
["S"] = "open_split",
["s"] = "open_vsplit",
["C"] = "close_node",
["R"] = "refresh",
["d"] = "delete",
["r"] = "rename",
["c"] = "copy_to_clipboard",
["x"] = "cut_to_clipboard",
["p"] = "paste_from_clipboard",
["A"] = "git_add_all",
["A"] = "git_add_all",
["gu"] = "git_unstage_file",
["ga"] = "git_add_file",
["gr"] = "git_revert_file",
["gc"] = "git_commit",
["gp"] = "git_push",
["gg"] = "git_commit_and_push",
},
},
renderers = {
directory = {
{ "indent" },
{ "icon" },
{ "name" },
{ "diagnostics", errors_only = true },
},
file = {
{ "indent" },
{ "icon" },
{ "name" },
{ "diagnostics" },
{ "git_status" },
},
},
},
}
}
}
}
require("neo-tree").setup(config)
vim.cmd [[
nnoremap <leader>n :NeoTreeFocus<cr>
nnoremap <C-n> :NeoTreeToggle<cr>
nnoremap <leader>n :Neotree reveal<cr>
nnoremap <C-n> :Neotree close<cr>
]]