From e4d005a070574929a72d17a0980f8c35f841fb85 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Tue, 25 Oct 2022 17:33:16 -0500 Subject: [PATCH] refactor(nvim): replace bufferline w/ barbar --- .../config/lua/plugins/configs/bufferline.lua | 18 --- .../primary/config/lua/plugins/mappings.lua | 8 +- .../primary/config/lua/plugins/plugins.lua | 14 +-- .../primary/config/lua/utils/funcs.lua | 116 ------------------ 4 files changed, 11 insertions(+), 145 deletions(-) delete mode 100755 dots/.nvim-environments/primary/config/lua/plugins/configs/bufferline.lua diff --git a/dots/.nvim-environments/primary/config/lua/plugins/configs/bufferline.lua b/dots/.nvim-environments/primary/config/lua/plugins/configs/bufferline.lua deleted file mode 100755 index abd50440..00000000 --- a/dots/.nvim-environments/primary/config/lua/plugins/configs/bufferline.lua +++ /dev/null @@ -1,18 +0,0 @@ -local bufferline = require('bufferline') - -bufferline.setup({ - options = { - numbers = function(opts) - return string.format('%s', opts.id) - end, - diagnostics = 'nvim_lsp', - offsets = { - { - filetype = 'NvimTree', - text = 'File Explorer', - highlight = 'Directory', - text_align = 'left', - }, - }, - }, -}) diff --git a/dots/.nvim-environments/primary/config/lua/plugins/mappings.lua b/dots/.nvim-environments/primary/config/lua/plugins/mappings.lua index e3a7665d..18643761 100755 --- a/dots/.nvim-environments/primary/config/lua/plugins/mappings.lua +++ b/dots/.nvim-environments/primary/config/lua/plugins/mappings.lua @@ -130,10 +130,10 @@ vim.keymap.set("n", "dl", dap.run_last, { silent = true, desc = "DAP: Ru vim.keymap.set("n", "/", ":CommentToggle", { silent = true, desc = "Toggle Comment" }) vim.keymap.set("v", "/", ":'<,'>CommentToggle", { silent = true, desc = "Toggle Selection Comment" }) --- Bufferline mappings -vim.keymap.set("n", "", ":BufferLineCyclePrev", { silent = true, desc = "Go to Previous Buffer" }) -vim.keymap.set("n", "", ":BufferLineCycleNext", { silent = true, desc = "Go to Next Buffer" }) -vim.keymap.set("n", "", require("utils.funcs").close_buffer, { silent = true, desc = "Close Buffer" }) +-- Buffer mappings +vim.keymap.set("n", "", ":BufferPrevious", { silent = true, desc = "Go to Previous Buffer" }) +vim.keymap.set("n", "", ":BufferNext", { silent = true, desc = "Go to Next Buffer" }) +vim.keymap.set("n", "", ":BufferClose", { silent = true, desc = "Close Buffer" }) -- Vim Notify Mappings vim.keymap.set("n", "nv", ":Telescope notify", { silent = true, desc = "Notifications: Search" }) diff --git a/dots/.nvim-environments/primary/config/lua/plugins/plugins.lua b/dots/.nvim-environments/primary/config/lua/plugins/plugins.lua index 7585a735..88800112 100755 --- a/dots/.nvim-environments/primary/config/lua/plugins/plugins.lua +++ b/dots/.nvim-environments/primary/config/lua/plugins/plugins.lua @@ -80,21 +80,21 @@ return packer.startup({ }) -- Tab Line at top of editor + use({ - "akinsho/nvim-bufferline.lua", - after = "nvim-web-devicons", - requires = { "nvim-web-devicons" }, + "romgrk/barbar.nvim", + requires = { "kyazdani42/nvim-web-devicons" }, config = function() - require("plugins.configs.bufferline") + require("bufferline").setup({ + animation = true, + auto_hide = true, + }) end, }) -- Statusline. use({ "nvim-lualine/lualine.nvim", - after = { - "nvim-bufferline.lua", - }, config = function() require("plugins.configs.statusline") end, diff --git a/dots/.nvim-environments/primary/config/lua/utils/funcs.lua b/dots/.nvim-environments/primary/config/lua/utils/funcs.lua index 954ad1bb..c7f687bd 100755 --- a/dots/.nvim-environments/primary/config/lua/utils/funcs.lua +++ b/dots/.nvim-environments/primary/config/lua/utils/funcs.lua @@ -1,121 +1,5 @@ local U = {} -U.close_buffer = function(force) - -- Yanked from NvChad, thanks to them. This saves - -- a lot of pain - - -- This is a modification of a NeoVim plugin from - -- Author: ojroques - Olivier Roques - -- Src: https://github.com/ojroques/nvim-bufdel - - -- Options - local opts = { - next = 'cycle', -- how to retrieve the next buffer - quit = false, -- exit when last buffer is deleted - --TODO make this a chadrc flag/option - } - - -- ---------------- - -- Helper functions - -- ---------------- - - -- Switch to buffer 'buf' on each window from list 'windows' - local function switch_buffer(windows, buf) - local cur_win = vim.fn.winnr() - for _, winid in ipairs(windows) do - vim.cmd(string.format('%d wincmd w', vim.fn.win_id2win(winid))) - vim.cmd(string.format('buffer %d', buf)) - end - vim.cmd(string.format('%d wincmd w', cur_win)) -- return to original window - end - - -- Select the first buffer with a number greater than given buffer - local function get_next_buf(buf) - local next = vim.fn.bufnr('#') - if opts.next == 'alternate' and vim.fn.buflisted(next) == 1 then - return next - end - for i = 0, vim.fn.bufnr('$') - 1 do - next = (buf + i) % vim.fn.bufnr('$') + 1 -- will loop back to 1 - if vim.fn.buflisted(next) == 1 then - return next - end - end - end - - -- ---------------- - -- End helper functions - -- ---------------- - - local buf = vim.fn.bufnr() - if vim.fn.buflisted(buf) == 0 then -- exit if buffer number is invalid - vim.cmd('close') - return - end - - if #vim.fn.getbufinfo({ buflisted = 1 }) < 2 then - if opts.quit then - -- exit when there is only one buffer left - if force then - vim.cmd('qall!') - else - vim.cmd('confirm qall') - end - return - end - - local chad_term, _ = pcall(function() - return vim.api.nvim_buf_get_var(buf, 'term_type') - end) - - if chad_term then - -- Must be a window type - vim.cmd(string.format('setlocal nobl', buf)) - vim.cmd('enew') - return - end - -- don't exit and create a new empty buffer - vim.cmd('enew') - vim.cmd('bp') - end - - local next_buf = get_next_buf(buf) - local windows = vim.fn.getbufinfo(buf)[1].windows - - -- force deletion of terminal buffers to avoid the prompt - if force or vim.fn.getbufvar(buf, '&buftype') == 'terminal' then - local chad_term, type = pcall(function() - return vim.api.nvim_buf_get_var(buf, 'term_type') - end) - - -- TODO this scope is error prone, make resilient - if chad_term then - if type == 'wind' then - -- hide from bufferline - vim.cmd(string.format('%d bufdo setlocal nobl', buf)) - -- swtich to another buff - -- TODO switch to next bufffer, this works too - vim.cmd('BufferLineCycleNext') - else - local cur_win = vim.fn.winnr() - -- we can close this window - vim.cmd(string.format('%d wincmd c', cur_win)) - return - end - else - switch_buffer(windows, next_buf) - vim.cmd(string.format('bd! %d', buf)) - end - else - switch_buffer(windows, next_buf) - vim.cmd(string.format('silent! confirm bd %d', buf)) - end - -- revert buffer switches if user has canceled deletion - if vim.fn.buflisted(buf) == 1 then - switch_buffer(windows, buf) - end -end - U.rgbToHex = function(rgb) return string.format('#%06x', rgb) end