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

Neovim plugin for navigating between buffers

License

NotificationsYou must be signed in to change notification settings

francescarpi/buffon.nvim

Repository files navigation

GitHub Workflow StatusLua

buffon.nvim logo

Buffon is yet another plugin for navigating between buffers inNeovim. The nameBuffon comes from the combination ofBuffer andNavigation, creating the amusing wordbuffon, referencing the medieval jester who entertained the king.

This plugin is inspired byharpoon andtide. Both are fantastic, but they didn't quite fit my workflow.

Things I like and dislike about these plugins:

Harpoon

LikesDislikes
* Data persistence* Having to select which buffers to work with
* Buffers can be sorted* Constantly having to open and close the window to see which buffers are selected, change the order, delete them, etc.
* Good API
* Tests

Tide

LikesDislikes
* Pleasant and beautiful interface* Having to select which buffers to work with
* Shortcuts to access a buffer directly* Buffers cannot be sorted
* Always having the buffer list visible* No persistence

Based on this, I createdBuffon with the best of both plugins, perfectly adapting to my way of working.

🎯 What Buffon offers

  • Simple and minimalist interface
  • Always visible interface
  • Data persistence, storing the cursor position
  • Works withall open buffers
  • Buffers can be:
    • Sorted: Move one position up/down, send to the beginning or end of the list
    • Closed: You can close one buffer, all, those above, those below, or the "others"
    • Navigate between previous and next buffer
    • Access a specific buffer
    • Toggle between the last used buffer
    • Reopen closed buffer
    • Shows modified buffer indicator
    • Organize buffers into pages
  • Help window to see the shortcuts

Note

If you like all these features and the plugin also adapts to your needs, I would greatly appreciate it if youclick on the star.

📦 Installation

Note

require neovim 0.10.0+

Usinglazy:

return {  {"francescarpi/buffon.nvim",branch="main",---@typeBuffonConfigopts= {--- Add your config here    },dependencies= {"nvim-tree/nvim-web-devicons","nvim-lua/plenary.nvim",    },  },}

⚙️ Default Configuration

Below you can see the default configuration, which you can adjust to your liking in the setup. For example:

return {  {"francescarpi/buffon.nvim",branch="main",---@typeBuffonConfigopts= {cyclic_navigation=true,    },dependencies= {"nvim-tree/nvim-web-devicons","nvim-lua/plenary.nvim",    },  },}

Default configuration:

Take a look at the default shortcuts for navigating between buffers, changing their order, or closing them:

{cyclic_navigation=true,--- possible values:---   "start": buffers are added at the begginning of the buffers list---   "end": buffers are added at the end of the list---   "after": are added after the active buffernew_buffer_position="end",num_pages=2,open= {by_default=true,offset= {x=0,y=0,    },ignore_ft= {"gitcommit","gitrebase",    },default_position="top_right"  },--- Buffers that should be ignored by buffon--- It accepts a list of regex patternsignore_buff_names= {"diffpanel_",  },sort_buffers_by_loaded_status=false,theme= {unloaded_buffer="#404040",shortcut="#CC7832",active="#51afef",unsaved_indicator="#f70067",  },leader_key=";",mapping_chars="qweryuiop",keybindings= {goto_next_buffer="<s-j>",goto_previous_buffer="<s-k>",move_buffer_up="<s-l>",move_buffer_down="<s-h>",move_buffer_top="<s-t>",move_buffer_bottom="<s-b>",toggle_buffon_window="<buffonleader>n",--- Toggle window position allows moving the main window position--- between top-right and bottom-right positionstoggle_buffon_window_position="<buffonleader>nn",switch_previous_used_buffer="<buffonleader><buffonleader>",close_buffer="<buffonleader>d",close_buffers_above="<buffonleader>v",close_buffers_below="<buffonleader>b",close_all_buffers="<buffonleader>cc",close_others="<buffonleader>cd",reopen_recent_closed_buffer="<buffonleader>t",show_help="<buffonleader>h",previous_page="<buffonleader>z",next_page="<buffonleader>x",move_to_previous_page="<buffonleader>a",move_to_next_page="<buffonleader>s",  },}

Tip

If you usenvim-lspconfig, thes-k shortcut (goto previous) may collide with thelsp one to view the documentation. In my case, I have this shortcut remapped to:

vim.keymap.set("n","c-l",vim.lsp.buf.hover)

Disable keybindings

The keybindings shown in the following list can be deactivated. The reason for this is that some people may not be interested in using the functionality to close buffers, move them, etc.

{goto_next_buffer,goto_previous_buffer,move_buffer_up,move_buffer_down,move_buffer_top,move_buffer_bottom,switch_previous_used_buffer,close_buffer,close_buffers_above,close_buffers_below,close_all_buffers,close_others,reopen_recent_closed_buffer,}

To do this, you only have to assign the string "false" or leave it blank in the configuration. For example:

{opts= {keybindings= {close_buffer="false"close_others=""    },  },}

Theming

The interface colors can be customized to your liking. There are four elements that can be personalized:

  1. Unloaded buffers (BuffonUnloadedBuffer)
  2. Shortcut (BuffonShortcut)
  3. Active buffers (BuffonActive)
  4. Modified buffer indicator (BuffonUnsavedIndicator)
buffon.nvim highlight groups

Note

The names of the Neovim highlight groups are indicated in parentheses.

There are two ways to customize the colors:

  1. Use Neovim's API to change the colors. For example:
vim.api.nvim_set_hl(0,"BuffonUnloadedBuffer", {fg="#404040"})
  1. Use Buffon's own configuration. In thetheme node, you can specify the different colors for each group.

Note

If a highlight group exists in Neovim, it will take precendence over the one specified in Buffon's configuration. Therefore, if you want to change the color of a highlight group, you must first remove it withvim.api.nvim_set_hl(0, "BuffonUnloadedBuffer", { fg = nil }) and then specify the new color. This is because if a colorscheme is installed that has a defined highlight group, it will take precedence over the one specified in Buffon's configuration.

📸 Screenshots

Buffon window, showing the buffer list:

Basic

Showing the help window:

With help

Note

If you are a fan of thecatpuccin theme, it is already integrated with buffon ;)

🔌 Extensions

Note

You can view all available extensionshere

You can build extensions for Buffon by using therequire("buffon").add() function. The function expects a callback function which has themaincontroller as its first parameter. This way you can manipulate Buffon in whichever way you want:

require("buffon").add(function (maincontroller)vim.notify(vim.inspect(maincontroller.config))end)

This also allows you to make plugins which other people can use too, by simply adding them to their config:

return {"plugin-author/plugin-repo",opts= {},...}

The plugin might have following structure:

localM= {}localconfig= {}---@typeBuffonPluginFunc add this for better completionlocalfunctioninitialize_plugin(maincontroller)ifconfig.remap["x"]thenmaincontroller.config.mapping_chars["x"]="z"elsemaincontroller.config.mapping_chars=""endendfunctionM.setup(opts)config=optsrequire("buffon").add(initialize_plugin)endreturnM

The function will be executed as soon as Buffon is fully set up.

If you've built an extension, feel free to add it to theextensions file!

I hope you like it and enjoy it!


[8]ページ先頭

©2009-2025 Movatter.jp