From 9f0fe3972747f51c7ed7cd6bfb8dd02ca7b3fb8f Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 15 Aug 2021 00:41:05 +0800 Subject: [PATCH] Change bufferline plugin to nvim-bufferline It looks better than barbar.nvim, IMO. --- lua/config/barbar.lua | 70 ---------------------------------- lua/config/nvim-bufferline.lua | 45 ++++++++++++++++++++++ lua/plugins.lua | 2 +- 3 files changed, 46 insertions(+), 71 deletions(-) delete mode 100644 lua/config/barbar.lua create mode 100644 lua/config/nvim-bufferline.lua diff --git a/lua/config/barbar.lua b/lua/config/barbar.lua deleted file mode 100644 index a4d02e1..0000000 --- a/lua/config/barbar.lua +++ /dev/null @@ -1,70 +0,0 @@ --- Set barbar's options -vim.g.bufferline = { - -- Enable/disable animations - animation = true, - - -- Enable/disable auto-hiding the tab bar when there is a single buffer - auto_hide = false, - - -- Enable/disable current/total tabpages indicator (top right corner) - tabpages = true, - - -- Enable/disable close button - closable = true, - - -- Enables/disable clickable tabs - -- - left-click: go to buffer - -- - middle-click: delete buffer - clickable = true, - - -- Excludes buffers from the tabline - exclude_ft = {'javascript', 'qf'}, - exclude_name = {'package.json'}, - - -- Enable/disable icons - -- if set to 'numbers', will show buffer index in the tabline - -- if set to 'both', will show buffer index and icons in the tabline - icons = 'buffer_numbers', - - -- If set, the icon color will follow its corresponding buffer - -- highlight group. By default, the Buffer*Icon group is linked to the - -- Buffer* group (see Highlighting below). Otherwise, it will take its - -- default value as defined by devicons. - icon_custom_colors = false, - - -- Configure icons on the bufferline. - icon_separator_active = '', - icon_separator_inactive = '▎', - icon_close_tab = '', - icon_close_tab_modified = '●', - icon_pinned = '車', - - -- If true, new buffers will be inserted at the end of the list. - -- Default is to insert after current buffer. - insert_at_end = false, - - -- Sets the maximum padding width with which to surround each tab - maximum_padding = 1, - - -- Sets the maximum buffer name length. - maximum_length = 30, - - -- If set, the letters for each buffer in buffer-pick mode will be - -- assigned based on their name. Otherwise or in case all letters are - -- already assigned, the behavior is to assign letters in order of - -- usability (see order below) - semantic_letters = true, - - -- New buffer letters are assigned in this order. This order is - -- optimal for the qwerty keyboard layout but might need adjustement - -- for other layouts. - letters = 'asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERUTYQP', - - -- Sets the name of unnamed buffers. By default format is "[Buffer X]" - -- where X is the buffer number. But only a static string is accepted here. - no_name_title = 'No name', -} - -vim.cmd 'hi BufferCurrent guibg=#85d3f2 guifg=#2c2e34' -vim.cmd 'hi BufferCurrentIndex guibg=#85d3f2 guifg=#2c2e34' -vim.cmd 'hi link BufferInactiveIndex BufferInactive' diff --git a/lua/config/nvim-bufferline.lua b/lua/config/nvim-bufferline.lua new file mode 100644 index 0000000..8697030 --- /dev/null +++ b/lua/config/nvim-bufferline.lua @@ -0,0 +1,45 @@ +require('bufferline').setup { + options = { + numbers = "buffer_id", + number_style = "superscript", + mappings = false, + close_command = "bdelete! %d", + right_mouse_command = nil, + left_mouse_command = "buffer %d", + middle_mouse_command = nil, + indicator_icon = '▎', + buffer_close_icon = '', + modified_icon = '●', + close_icon = '', + left_trunc_marker = '', + right_trunc_marker = '', + max_name_length = 18, + max_prefix_length = 15, + tab_size = 10, + diagnostics = false, + custom_filter = function(bufnr) + -- if the result is false, this buffer will be shown, otherwise, this + -- buffer will be hidden. + + -- filter out filetypes you don't want to see + local exclude_ft = {'qf', 'fugitive', 'git'} + local cur_ft = vim.bo[bufnr].filetype + local should_filter = vim.tbl_contains(exclude_ft, cur_ft) + + if should_filter then + return false + end + + return true + end, + show_buffer_icons = false, + show_buffer_close_icons = true, + show_close_icon = true, + show_tab_indicators = true, + persist_buffer_sort = true, -- whether or not custom sorted buffers should persist + separator_style = "slant", + enforce_regular_tabs = false, + always_show_bufferline = true, + sort_by = 'id' + } +} diff --git a/lua/plugins.lua b/lua/plugins.lua index 943295f..a8fd53a 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -102,7 +102,7 @@ require('packer').startup( use 'vim-airline/vim-airline-themes' use 'vim-airline/vim-airline' - use {'romgrk/barbar.nvim', config = [[require('config.barbar')]]} + use {'akinsho/nvim-bufferline.lua', config = [[require('config.nvim-bufferline')]]} -- fancy start screen use {'mhinz/vim-startify'}