From dc6196ee295fa92b1a20a436be5d539f44475e29 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 26 Jun 2021 19:37:24 +0200 Subject: Fix barbar integration with nvim-tree (#523) - Add an offset to display NvimTree buffer in barbar. It won't work correctly if you enable "vim.g.nvim_tree_quit_on_open". - Add which-key support to barbar to enable missing mappings. Co-authored-by: Christian Chiarulli --- lua/lv-nvimtree/init.lua | 17 +++++++++++++++++ lua/lv-which-key/init.lua | 21 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lua/lv-nvimtree/init.lua b/lua/lv-nvimtree/init.lua index 934a321b..4b8c3973 100644 --- a/lua/lv-nvimtree/init.lua +++ b/lua/lv-nvimtree/init.lua @@ -20,6 +20,7 @@ vim.g.nvim_tree_indent_markers = 1 -- "0 by default, this option shows indent ma vim.g.nvim_tree_follow = 1 -- "0 by default, this option allows the cursor to be updated when entering a buffer vim.g.nvim_tree_auto_close = O.auto_close_tree -- 0 by default, closes the tree when it's the last window vim.g.nvim_tree_auto_ignore_ft = 'startify' --empty by default, don't auto open tree on specific filetypes. +vim.g.nvim_tree_quit_on_open = 0 -- this doesn't play well with barbar local tree_cb = require'nvim-tree.config'.nvim_tree_callback vim.g.nvim_tree_bindings = { -- [""] = ":YourVimFunction()", @@ -63,3 +64,19 @@ vim.g.nvim_tree_icons = { git = {unstaged = "", staged = "✓", unmerged = "", renamed = "➜", untracked = ""}, folder = {default = "", open = "", empty = "", empty_open = "", symlink = ""} } + +local view = require'nvim-tree.view' + +local _M = {} +_M.toggle_tree = function() + if view.win_open() then + require'nvim-tree'.close() + require'bufferline.state'.set_offset(0) + else + require'bufferline.state'.set_offset(31, 'File Explorer') + require'nvim-tree'.find_file(true) + end + +end + +return _M diff --git a/lua/lv-which-key/init.lua b/lua/lv-which-key/init.lua index 27f1b406..d98ea3ed 100644 --- a/lua/lv-which-key/init.lua +++ b/lua/lv-which-key/init.lua @@ -52,7 +52,7 @@ vim.g.mapleader = ' ' vim.api.nvim_set_keymap('n', 'h', ':let @/=""', {noremap = true, silent = true}) -- explorer -vim.api.nvim_set_keymap('n', 'e', ':NvimTreeToggle', {noremap = true, silent = true}) +vim.api.nvim_set_keymap('n', 'e', ":lua require'lv-nvimtree'.toggle_tree()", {noremap = true, silent = true}) -- telescope vim.api.nvim_set_keymap('n', 'f', ':Telescope find_files', {noremap = true, silent = true}) @@ -74,6 +74,24 @@ vim.api.nvim_set_keymap('n', 'p', ":lua require'telescope'.extensions.pr -- TODO create entire treesitter section local mappings = { + + ["/"] = "Comment", + ["c"] = "Close Buffer", + ["e"] = "Explorer", + ["f"] = "Find File", + ["h"] = "No Highlight", + ["p"] = "Projects", + b = { + name = "+Buffers", + j = {"BufferPick", "jump to buffer"}, + w = {"BufferWipeout", "wipeout buffer"}, + e = {"BufferCloseAllButCurrent", "close all but current buffer"}, + h = {"BufferCloseBuffersLeft", "close all buffers to the left"}, + l = {"BufferCloseBuffersRight", "close all BufferLines to the right"}, + D = {"BufferOrderByDirectory", "sort BufferLines automatically by directory"}, + L = {"BufferOrderByLanguage", "sort BufferLines automatically by language"}, + }, + ["/"] = {"CommentToggle", "Comment"}, [";"] = {"Dashboard", "Dashboard"}, ["c"] = {"BufferClose", "Close Buffer"}, @@ -81,6 +99,7 @@ local mappings = { ["f"] = {"Telescope find_files", "Find File"}, ["h"] = {"set hlsearch!", "No Highlight"}, ["p"] = {"lua require'telescope'.extensions.project.project{}", "Projects"}, + d = { name = "Diagnostics", t = {"TroubleToggle", "trouble"}, -- cgit v1.2.3