From 1bcf68ac25c1a5bcfaecd72b1c58c0c1df200258 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Mon, 22 Apr 2024 20:47:03 +0200 Subject: [PATCH] Open files in new tab --- lua/plugins/nvim-tree.lua | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lua/plugins/nvim-tree.lua b/lua/plugins/nvim-tree.lua index ade4ab5..2a6098a 100644 --- a/lua/plugins/nvim-tree.lua +++ b/lua/plugins/nvim-tree.lua @@ -8,10 +8,35 @@ return { vim.g.loaded_netrwPlugin = 1 vim.opt.termguicolors = true - require('nvim-tree').setup() + require('nvim-tree').setup({ + tab = { + sync = { + open = true, + close = true + } + }, + on_attach = function(bufnr) + local api = require('nvim-tree.api') + local lib = require('nvim-tree.lib') + api.config.mappings.default_on_attach(bufnr) + + local function opts(desc) + return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + vim.keymap.set('n', '', function() + local node = lib.get_node_at_cursor() + api.node.open.tab() + if node.type == 'file' then + vim.cmd('wincmd l') + vim.cmd('tabprevious') + end + api.tree.focus() + end, opts('Open: New Tab (unfocused)')) + end + }) local api = require('nvim-tree.api') - vim.keymap.set('n', 'e', api.tree.open, { desc = "Open file explorer" }) - vim.keymap.set('n', 'E', api.tree.close, { desc = "Close file explorer" }) + vim.keymap.set('n', 'e', api.tree.toggle, { desc = "Toggle file explorer" }) end }