LunarVim/lua/lvim/core/nvimtree.lua

210 lines
5.3 KiB
Lua
Raw Normal View History

2021-06-28 04:11:33 +02:00
local M = {}
local Log = require "lvim.core.log"
function M.config()
local vim_show_icons = lvim.use_icons and 1 or 0
lvim.builtin.nvimtree = {
active = true,
on_config_done = nil,
setup = {
2021-11-29 09:12:13 +01:00
disable_netrw = true,
hijack_netrw = true,
open_on_setup = false,
open_on_setup_file = false,
sort_by = "name",
2022-03-02 15:06:06 +01:00
ignore_buffer_on_setup = false,
2021-11-29 09:12:13 +01:00
ignore_ft_on_setup = {
"startify",
"dashboard",
"alpha",
},
auto_reload_on_write = true,
hijack_unnamed_buffer_when_opening = false,
hijack_directories = {
enable = true,
auto_open = true,
},
2021-11-29 09:12:13 +01:00
open_on_tab = false,
hijack_cursor = false,
update_cwd = false,
diagnostics = {
enable = lvim.use_icons,
show_on_dirs = false,
icons = {
hint = "",
info = "",
warning = "",
error = "",
},
},
2021-11-29 09:12:13 +01:00
update_focused_file = {
enable = true,
update_cwd = true,
ignore_list = {},
},
system_open = {
cmd = nil,
args = {},
},
git = {
enable = true,
ignore = false,
2021-11-29 09:12:13 +01:00
timeout = 200,
},
view = {
width = 30,
2021-11-29 09:12:13 +01:00
height = 30,
hide_root_folder = false,
side = "left",
preserve_window_proportions = false,
mappings = {
custom_only = false,
2021-11-29 09:12:13 +01:00
list = {},
},
number = false,
relativenumber = false,
signcolumn = "yes",
},
renderer = {
indent_markers = {
enable = false,
icons = {
corner = "",
edge = "",
none = " ",
},
},
icons = {
webdev_colors = lvim.use_icons,
},
},
2021-11-29 09:12:13 +01:00
filters = {
dotfiles = false,
custom = { "node_modules", "\\.cache" },
exclude = {},
},
trash = {
cmd = "trash",
require_confirm = true,
2021-11-29 09:12:13 +01:00
},
log = {
enable = false,
truncate = false,
types = {
all = false,
config = false,
copy_paste = false,
diagnostics = false,
git = false,
profile = false,
},
},
actions = {
use_system_clipboard = true,
change_dir = {
enable = true,
global = false,
restrict_above_cwd = false,
},
open_file = {
quit_on_open = false,
resize_window = false,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
buftype = { "nofile", "terminal", "help" },
},
},
},
},
},
show_icons = {
git = vim_show_icons,
folders = vim_show_icons,
files = vim_show_icons,
folder_arrows = vim_show_icons,
},
git_hl = 1,
root_folder_modifier = ":t",
icons = {
default = "",
symlink = "",
git = {
unstaged = "",
staged = "S",
unmerged = "",
renamed = "",
deleted = "",
untracked = "U",
ignored = "",
},
folder = {
default = "",
open = "",
empty = "",
empty_open = "",
symlink = "",
},
},
}
lvim.builtin.which_key.mappings["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" }
end
function M.setup()
local status_ok, nvim_tree = pcall(require, "nvim-tree")
2021-07-18 13:27:06 +02:00
if not status_ok then
Log:error "Failed to load nvim-tree"
2021-07-18 13:27:06 +02:00
return
end
2021-04-15 06:17:48 +02:00
for opt, val in pairs(lvim.builtin.nvimtree) do
vim.g["nvim_tree_" .. opt] = val
end
-- Implicitly update nvim-tree when project module is active
if lvim.builtin.project.active then
lvim.builtin.nvimtree.respect_buf_cwd = 1
lvim.builtin.nvimtree.setup.update_cwd = true
lvim.builtin.nvimtree.setup.update_focused_file = { enable = true, update_cwd = true }
end
local function telescope_find_files(_)
require("lvim.core.nvimtree").start_telescope "find_files"
end
local function telescope_live_grep(_)
require("lvim.core.nvimtree").start_telescope "live_grep"
end
-- Add useful keymaps
if #lvim.builtin.nvimtree.setup.view.mappings.list == 0 then
lvim.builtin.nvimtree.setup.view.mappings.list = {
{ key = { "l", "<CR>", "o" }, action = "edit", mode = "n" },
{ key = "h", action = "close_node" },
{ key = "v", action = "vsplit" },
{ key = "C", action = "cd" },
{ key = "gtf", action = "telescope_find_files", action_cb = telescope_find_files },
{ key = "gtg", action = "telescope_live_grep", action_cb = telescope_live_grep },
}
end
nvim_tree.setup(lvim.builtin.nvimtree.setup)
if lvim.builtin.nvimtree.on_config_done then
lvim.builtin.nvimtree.on_config_done(nvim_tree)
end
end
function M.start_telescope(telescope_mode)
local node = require("nvim-tree.lib").get_node_at_cursor()
local abspath = node.link_to or node.absolute_path
local is_folder = node.open ~= nil
local basedir = is_folder and abspath or vim.fn.fnamemodify(abspath, ":h")
require("telescope.builtin")[telescope_mode] {
cwd = basedir,
}
end
2021-06-28 04:11:33 +02:00
return M