init
This commit is contained in:
68
lua/config/nvim-tree.lua
Normal file
68
lua/config/nvim-tree.lua
Normal file
@ -0,0 +1,68 @@
|
||||
-- Настройка nvim-tree
|
||||
require("nvim-tree").setup({
|
||||
sort = {
|
||||
sorter = "case_sensitive",
|
||||
},
|
||||
view = {
|
||||
width = 40,
|
||||
},
|
||||
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", ".epub", ".fb2"
|
||||
}
|
||||
|
||||
-- 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 })
|
||||
|
||||
|
||||
vim.api.nvim_create_autocmd("DirChanged", {
|
||||
callback = function()
|
||||
local new_dir = vim.fn.getcwd() -- Получаем текущую рабочую директорию
|
||||
require("nvim-tree.api").tree.change_root(new_dir)
|
||||
-- Здесь можно добавить любые действия, например, логирование или обновление плагинов
|
||||
end,
|
||||
})
|
||||
Reference in New Issue
Block a user