SexNvim/lua/config/nvim-tree.lua
СЕМА 6f9fcff8fa - random colorscheme (common-settings)
- заменить Enter на Tab в cmp-path
- Теперь nvim tree стал более userfriendly: Enter открывает директорию как корневую, чтобы посмотреть просто ее содержимое Tab, так же Enter заменяет s(открытие файлов типа docx,pdf и тд. во внешнем приложении) так же удалены некоторые лишние на мой взгляд плагины: wichkey vimtex(возможно в будущем верну)
2025-03-09 07:45:59 +03:00

60 lines
1.6 KiB
Lua

-- Настройка nvim-tree
require("nvim-tree").setup({
sort = {
sorter = "case_sensitive",
},
view = {
width = 50,
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
actions = {
open_file = {
quit_on_open = true, -- закрывать дерево при открытии файла
},
},
on_attach = function(bufnr)
local api = require("nvim-tree.api")
-- Apply default mappings
api.config.mappings.default_on_attach(bufnr)
-- Remove default C-] mapping
vim.keymap.del("n", "<C-]>", { buffer = bufnr })
-- Define file extensions to handle with system open
local special_extensions = {
".pdf", ".png", ".jpeg", ".jpg", ".doc", ".docx"
}
-- Helper function to check file extension
local function has_special_extension(node)
for _, ext in ipairs(special_extensions) do
if node.name:match("%.?[^.]+$") == ext then
return true
end
end
return false
end
-- Create combined CR mapping
vim.keymap.set("n", "<CR>", function()
local node = api.tree.get_node_under_cursor()
if node and has_special_extension(node) then
api.node.run.system() -- Open file in system
else
api.node.open.edit() -- Default open file behavior
api.tree.change_root_to_node() -- Change root to node
end
end, { buffer = bufnr })
end,
})
-- Глобальные бинды для nvim-tree
vim.keymap.set("n", "<Leader>e", ":NvimTreeToggle<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<Leader>q", ":NvimTreeFindFile<CR>", { noremap = true, silent = true })