Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The neovim tabline plugin.

NotificationsYou must be signed in to change notification settings

romgrk/barbar.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

demo

barbar.nvim

Tabs, as understood by any other editor.

barbar.nvim is a tabline plugin with re-orderable, auto-sizing, clickable tabs,icons, nice highlighting, sort-by commands and a magic jump-to-buffer mode. Plusthe tab names are made unique when two filenames match.

In jump-to-buffer mode, tabs display a target letter instead of their icon. Jump toany buffer by simply typing their target letter. Even better, the target letterstays constant for the lifetime of the buffer, so if you're working with a set offiles you can even type the letter ahead from memory.

Table of content

Install

Requirements:

  • Neovim v0.7+

Optional Requirements:

require('lazy').setup {  {'romgrk/barbar.nvim',dependencies= {'lewis6991/gitsigns.nvim',-- OPTIONAL: for git status'nvim-tree/nvim-web-devicons',-- OPTIONAL: for file icons    },init=function()vim.g.barbar_auto_setup=falseend,opts= {-- lazy.nvim will automatically call setup for you. put your options here, anything missing will use the default:-- animation = true,-- insert_at_start = true,-- …etc.    },version='^1.0.0',-- optional: only update when a new 1.x version is released  },}
-- These optional plugins should be loaded directly because of a bug in Packer lazy loadinguse'nvim-tree/nvim-web-devicons'-- OPTIONAL: for file iconsuse'lewis6991/gitsigns.nvim'-- OPTIONAL: for git statususe'romgrk/barbar.nvim'
Plug'nvim-tree/nvim-web-devicons'" OPTIONAL: for file iconsPlug'lewis6991/gitsigns.nvim'" OPTIONAL: for git statusPlug'romgrk/barbar.nvim'

Features

Re-order tabs

reorder

Auto-sizing tabs, fill the space when available

resize

Jump-to-buffer mode

jump

Type a letter to jump to a buffer. Letters stay constant for the lifetime of the buffer.By default, letters are assigned based on buffer name, egREADME.md will get letterr.You can change this so that letters are assigned based on usability:home row (asdfjkl;gh) first, then other rows.

Sort tabs automatically

jump

:BufferOrderByName,:BufferOrderByDirectory,:BufferOrderByLanguage,:BufferOrderByWindowNumber,:BufferOrderByBufferNumber

Clickable & closable tabs

click

Left-click to go, middle-click or close button to close. Don't forget toset mouse+=a.

Unique names when filenames match

unique-name

Pinned buffers

pinned

bbye.vim for closing buffers

A modified version ofbbye.vim is included in thisplugin to close buffers without messing with your window layout and more. AvailableasBufferClose andbufferline#bbye#delete(buf).

Scrollable tabs, to always show the current buffer

scroll

Offset bufferline when showing sidebars

filetree-with-offset

Usage

Mappings & commands

Vim script

No default mappings are provided, here is an example. It is recommended to usetheBufferClose command to close buffers instead ofbdelete because it willnot mess your window layout.

Note

In the below key mappings, the Alt key is being used.If you are using a terminal like iTerm on Mac, youwill want to make sure that your Option key is properlymapped to Alt. Its under Profiles > Keys, select Esc+

" Move to previous/nextnnoremap<silent><A-,><Cmd>BufferPrevious<CR>nnoremap<silent><A-.><Cmd>BufferNext<CR>" Re-order to previous/nextnnoremap<silent><A-<><Cmd>BufferMovePrevious<CR>nnoremap<silent><A->><Cmd>BufferMoveNext<CR>" Goto buffer in position...nnoremap<silent><A-1><Cmd>BufferGoto 1<CR>nnoremap<silent><A-2><Cmd>BufferGoto 2<CR>nnoremap<silent><A-3><Cmd>BufferGoto 3<CR>nnoremap<silent><A-4><Cmd>BufferGoto 4<CR>nnoremap<silent><A-5><Cmd>BufferGoto 5<CR>nnoremap<silent><A-6><Cmd>BufferGoto 6<CR>nnoremap<silent><A-7><Cmd>BufferGoto 7<CR>nnoremap<silent><A-8><Cmd>BufferGoto 8<CR>nnoremap<silent><A-9><Cmd>BufferGoto 9<CR>nnoremap<silent><A-0><Cmd>BufferLast<CR>" Pin/unpin buffernnoremap<silent><A-p><Cmd>BufferPin<CR>" Goto pinned/unpinned buffer"                          :BufferGotoPinned"                          :BufferGotoUnpinned" Close buffernnoremap<silent><A-c><Cmd>BufferClose<CR>" Restore buffernnoremap<silent><A-s-c><Cmd>BufferRestore<CR>" Wipeout buffer"                          :BufferWipeout" Close commands"                          :BufferCloseAllButCurrent"                          :BufferCloseAllButVisible"                          :BufferCloseAllButPinned"                          :BufferCloseAllButCurrentOrPinned"                          :BufferCloseBuffersLeft"                          :BufferCloseBuffersRight" Magic buffer-picking modennoremap<silent><C-p><Cmd>BufferPick<CR>nnoremap<silent><C-s-p><Cmd>BufferPickDelete<CR>" Sort automatically by...nnoremap<silent><Space>bb<Cmd>BufferOrderByBufferNumber<CR>nnoremap<silent><Space>bn<Cmd>BufferOrderByName<CR>nnoremap<silent><Space>bd<Cmd>BufferOrderByDirectory<CR>nnoremap<silent><Space>bl<Cmd>BufferOrderByLanguage<CR>nnoremap<silent><Space>bw<Cmd>BufferOrderByWindowNumber<CR>" Other:" :BarbarEnable - enables barbar (enabled by default)" :BarbarDisable - very bad command, should never be used

Lua

localmap=vim.api.nvim_set_keymaplocalopts= {noremap=true,silent=true }-- Move to previous/nextmap('n','<A-,>','<Cmd>BufferPrevious<CR>',opts)map('n','<A-.>','<Cmd>BufferNext<CR>',opts)-- Re-order to previous/nextmap('n','<A-<>','<Cmd>BufferMovePrevious<CR>',opts)map('n','<A->>','<Cmd>BufferMoveNext<CR>',opts)-- Goto buffer in position...map('n','<A-1>','<Cmd>BufferGoto 1<CR>',opts)map('n','<A-2>','<Cmd>BufferGoto 2<CR>',opts)map('n','<A-3>','<Cmd>BufferGoto 3<CR>',opts)map('n','<A-4>','<Cmd>BufferGoto 4<CR>',opts)map('n','<A-5>','<Cmd>BufferGoto 5<CR>',opts)map('n','<A-6>','<Cmd>BufferGoto 6<CR>',opts)map('n','<A-7>','<Cmd>BufferGoto 7<CR>',opts)map('n','<A-8>','<Cmd>BufferGoto 8<CR>',opts)map('n','<A-9>','<Cmd>BufferGoto 9<CR>',opts)map('n','<A-0>','<Cmd>BufferLast<CR>',opts)-- Pin/unpin buffermap('n','<A-p>','<Cmd>BufferPin<CR>',opts)-- Goto pinned/unpinned buffer--                 :BufferGotoPinned--                 :BufferGotoUnpinned-- Close buffermap('n','<A-c>','<Cmd>BufferClose<CR>',opts)-- Wipeout buffer--                 :BufferWipeout-- Close commands--                 :BufferCloseAllButCurrent--                 :BufferCloseAllButPinned--                 :BufferCloseAllButCurrentOrPinned--                 :BufferCloseBuffersLeft--                 :BufferCloseBuffersRight-- Magic buffer-picking modemap('n','<C-p>','<Cmd>BufferPick<CR>',opts)map('n','<C-s-p>','<Cmd>BufferPickDelete<CR>',opts)-- Sort automatically by...map('n','<Space>bb','<Cmd>BufferOrderByBufferNumber<CR>',opts)map('n','<Space>bn','<Cmd>BufferOrderByName<CR>',opts)map('n','<Space>bd','<Cmd>BufferOrderByDirectory<CR>',opts)map('n','<Space>bl','<Cmd>BufferOrderByLanguage<CR>',opts)map('n','<Space>bw','<Cmd>BufferOrderByWindowNumber<CR>',opts)-- Other:-- :BarbarEnable - enables barbar (enabled by default)-- :BarbarDisable - very bad command, should never be used

Options

Note

If you're using Vim Script, just wrapsetup like this:

letg:barbar_auto_setup=v:false" disable auto-setuplua << EOF  require'barbar'.setup {…}EOF
vim.g.barbar_auto_setup=false-- disable auto-setuprequire'barbar'.setup {-- WARN: do not copy everything below into your config!--       It is just an example of what configuration options there are.--       The defaults are suitable for most people.-- Enable/disable animationsanimation=true,-- Automatically hide the tabline when there are this many buffers left.-- Set to any value >=0 to enable.auto_hide=false,-- Enable/disable current/total tabpages indicator (top right corner)tabpages=true,-- Enables/disable clickable tabs--  - left-click: go to buffer--  - middle-click: delete bufferclickable=true,-- Excludes buffers from the tablineexclude_ft= {'javascript'},exclude_name= {'package.json'},-- A buffer to this direction will be focused (if it exists) when closing the current buffer.-- Valid options are 'left' (the default), 'previous', and 'right'focus_on_close='left',-- Hide inactive buffers and file extensions. Other options are `alternate`, `current`, and `visible`.hide= {extensions=true,inactive=true},-- Disable highlighting alternate buffershighlight_alternate=false,-- Disable highlighting file icons in inactive buffershighlight_inactive_file_icons=false,-- Enable highlighting visible buffershighlight_visible=true,icons= {-- Configure the base icons on the bufferline.-- Valid options to display the buffer index and -number are `true`, 'superscript' and 'subscript'buffer_index=false,buffer_number=false,button='',-- Enables / disables diagnostic symbolsdiagnostics= {      [vim.diagnostic.severity.ERROR]= {enabled=true,icon=''},      [vim.diagnostic.severity.WARN]= {enabled=false},      [vim.diagnostic.severity.INFO]= {enabled=false},      [vim.diagnostic.severity.HINT]= {enabled=true},    },gitsigns= {added= {enabled=true,icon='+'},changed= {enabled=true,icon='~'},deleted= {enabled=true,icon='-'},    },filetype= {-- Sets the icon's highlight group.-- If false, will use nvim-web-devicons colorscustom_colors=false,-- Requires `nvim-web-devicons` if `true`enabled=true,    },separator= {left='',right=''},-- If true, add an additional separator at the end of the buffer listseparator_at_end=true,-- Configure the icons on the bufferline when modified or pinned.-- Supports all the base icon options.modified= {button=''},pinned= {button='',filename=true},-- Use a preconfigured buffer appearance— can be 'default', 'powerline', or 'slanted'preset='default',-- Configure the icons on the bufferline based on the visibility of a buffer.-- Supports all the base icon options, plus `modified` and `pinned`.alternate= {filetype= {enabled=false}},current= {buffer_index=true},inactive= {button='×'},visible= {modified= {buffer_number=false}},  },-- If true, new buffers will be inserted at the start/end of the list.-- Default is to insert after current buffer.insert_at_end=false,insert_at_start=false,-- Sets the maximum padding width with which to surround each tabmaximum_padding=1,-- Sets the minimum padding width with which to surround each tabminimum_padding=1,-- Sets the maximum buffer name length.maximum_length=30,-- Sets the minimum buffer name length.minimum_length=0,-- 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,-- Set the filetypes which barbar will offset itself forsidebar_filetypes= {-- Use the default values: {event = 'BufWinLeave', text = '', align = 'left'}NvimTree=true,-- Or, specify the text used for the offset:undotree= {text='undotree',align='center',-- *optionally* specify an alignment (either 'left', 'center', or 'right')    },-- Or, specify the event which the sidebar executes when leaving:    ['neo-tree']= {event='BufWipeout'},-- Or, specify all threeOutline= {event='BufWinLeave',text='symbols-outline',align='right'},  },-- New buffer letters are assigned in this order. This order is-- optimal for the qwerty keyboard layout but might need adjustment-- 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=nil,-- sorting optionssort= {-- tells barbar to ignore case differences while sorting buffersignore_case=true,  },}

Highlighting

Highlight groups are created in this way:Buffer<STATUS><PART>.

<STATUS>Meaning
AlternateThe:h alternate-file.
CurrentThe current buffer.
Inactive:h hidden-buffers and:h inactive-buffers.
Visible:h active-buffers which are not alternate or current.
<PART>Meaning
ADDEDGit status added.
BtnThe button that shows when a buffer is unpinned and unmodified.
CHANGEDGit status changed.
DELETEDGit status deleted.
ERRORDiagnostic errors.
HINTDiagnostic hints.
IconThe filetype icon (whenicons.filetype == {custom_colors = true, enabled = true}).
IndexThe buffer's position in the tabline.
INFODiagnostic info.
ModWhen the buffer is modified.
ModBtnThe button that shows when a buffer is modified.
NumberThe:h bufnr().
PinWhen the buffer is pinned.
PinBtnThe button that shows when a buffer is pinned.
SignThe separator between buffers.
SignRightThe separator between buffers.
TargetThe letter in buffer-pick mode.
WARNDiagnostic warnings.
  • e.g. the current buffer's highlight when modified isBufferCurrentMod

There are a few highlight groups which do not follow this rule. They are:

GroupUsage
BufferOffsetThe background of the header for asidebar_filetype
BufferScrollArrowThe arrow which shows to indicate that there are more buffers to the left or right of the scroll position.
BufferTabpageFillThe space between the open buffer list and the tabpage
BufferTabpagesThe color of the tabpages indicator.
BufferTabpagesSepThe separator between the tabpages count.

You can also use thedoom-one.vimcolorscheme that defines those groups and is also very pleasant as you could seein the demos above.

Integrations

To preserve buffer order while usingscope.nvim, you can add this to your config:

require('scope').setup {hooks= {pre_tab_leave=function()vim.api.nvim_exec_autocmds('User', {pattern='ScopeTabLeavePre'})-- [other statements]end,post_tab_enter=function()vim.api.nvim_exec_autocmds('User', {pattern='ScopeTabEnterPost'})-- [other statements]end,-- [other hooks]  },-- [other options]}

Sessions

barbar.nvim can restore the order that your buffers were in, as well as whether a buffer was pinned. To do this,sessionoptions must containglobals, and theUser SessionSavePre event must be executed before:mksession.

Here is amini.sessions config which can be used:

vim.opt.sessionoptions:append'globals'require'mini.sessions'.setup {hooks= {pre= {write=function()vim.api.nvim_exec_autocmds('User', {pattern='SessionSavePre'})end,    },  },}

Here is apersistence.nvim config which can be used:

require'persistence'.setup {options= {--[[<other options>,]]'globals'},pre_save=function()vim.api.nvim_exec_autocmds('User', {pattern='SessionSavePre'})end,}

Here is apersisted.nvim config which can be used:

vim.opt.sessionoptions:append'globals'vim.api.nvim_create_autocmd({'User'}, {pattern='PersistedSavePre',group=vim.api.nvim_create_augroup('PersistedHooks', {}),callback=function()vim.api.nvim_exec_autocmds('User', {pattern='SessionSavePre'})end,})

This plugin comes with support forresession.nvim through an extension. To enable, add the following snippet to your resession config:

extensions= {barbar= {},}

If usinglazy.nvim then ensure you add barbar.nvim as a dependency to resession, to ensure that the extension loads before resession.

Custom

You can add this snippet to your config to take advantage of our session integration:

vim.opt.sessionoptions:append'globals'vim.api.nvim_create_user_command('Mksession',function(attr)vim.api.nvim_exec_autocmds('User', {pattern='SessionSavePre'})-- Neovim 0.8+vim.cmd.mksession {bang=attr.bang,args=attr.fargs}-- Neovim 0.7vim.api.nvim_command('mksession'.. (attr.bangand'!'or'')..attr.args)end,  {bang=true,complete='file',desc='Save barbar with :mksession',nargs='?'})

Known Issues

Lightline

Barbar doesn't show up because lightline changes the tabline setting. Add:

letg:lightline={'enable': {'statusline':1,'tabline':0} }

Netrw

netrw has a lot of bugs which make it hard to support. It may work partially, but we will not make changes to barbar.nvim to work-aroundnetrw-specific bugs (e.g. #82).

You can use any otherfile explorer instead.

Sidebars On Startup

Thesidebar_filetypes option may not work as expected if your sidebar opens on startup. Seenvim-tree/nvim-tree.lua#2130 for details, and#421 for a workaround.

About

Barbar is called barbar because it's a bar, but it's also more than a bar:a "barbar".

It is pronounced like "Jar Jar" in "Jar Jar Binks", but with Bs.

No, barbar has nothing to do with barbarians.

License

  • barbar.nvim: Distributed under the terms of the JSON license.
  • bbye.vim: Distributed under the terms of the GNU Affero license.

[8]ページ先頭

©2009-2025 Movatter.jp