Skip to content

hernancerm/bufpin.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

145 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bufpin

Pin buffers for quick navigation.

bufpin.nvim demo

Problem

From https://github.com/ThePrimeagen/harpoon/tree/harpoon2:

You're working on a codebase. medium, large, tiny, whatever. You find yourself frequenting a small set of files and you are tired of using a fuzzy finder, :bnext & :bprev are getting too repetitive, alternate file doesn't quite cut it, etc etc.

Solution

Pin buffers and allow navigating to them via keymaps. The pinned bufs are drawn in the 'tabline'. Visually, this looks like tabs in a modern text editor, but the distinction is that the bufs are all manually tracked.

Features

  • Display the pinned bufs in the tabline.
  • Mouse support to left-click to edit buf and middle-click to remove buf.
  • Store the pinned bufs in session (:mksession) if vim.opt.ssop:append("globals").
  • Auto-hide the tabline when there are no pinned bufs.
  • Expose an API to track the pinned bufs.
  • Show file type icons.

Suggested complementary plugins:

Out of scope

Requirements

  • Neovim >= 0.11.0

Installation

Install with your favorite package manager. For example, using Neovim's builtin package manager, vim.pack:

vim.pack.add({
  "https://github.com/hernancerm/bufpin.nvim",
})

local opts = { silent = true }
vim.keymap.set("n", "<Leader>p", ":lua Bufpin.toggle()<CR>",         opts)
vim.keymap.set("n", "<Leader>w", ":lua Bufpin.remove()<CR>",         opts)
vim.keymap.set("n", "<Up>",      ":lua Bufpin.edit_left()<CR>",      opts)
vim.keymap.set("n", "<Down>",    ":lua Bufpin.edit_right()<CR>",     opts)
vim.keymap.set("n", "<Left>",    ":lua Bufpin.move_to_left()<CR>",   opts)
vim.keymap.set("n", "<Right>",   ":lua Bufpin.move_to_right()<CR>",  opts)
vim.keymap.set("n", "<F1>",      ":lua Bufpin.edit_by_index(1)<CR>", opts)
vim.keymap.set("n", "<F2>",      ":lua Bufpin.edit_by_index(2)<CR>", opts)
vim.keymap.set("n", "<F3>",      ":lua Bufpin.edit_by_index(3)<CR>", opts)
vim.keymap.set("n", "<F4>",      ":lua Bufpin.edit_by_index(4)<CR>", opts)

Some things to notice:

  • require("bufpin").setup() does not need to be called. You may call it to configure the plugin.
  • The plugin does not create keymaps, you need to define them as shown above.

Default config

require("bufpin").setup({
  auto_hide_tabline = true,
  exclude = function(_) end,
  use_mini_bufremove = true,
  icons_style = "monochrome_selected",
  ghost_buf_enabled = true,
  remove_with = "delete",
})

Documentation

Please refer to the help file: bufpin.txt.

JetBrains IDEs

To get a similar experience in JetBrains IDEs follow these instructions:

  • IDE: In Settings set the tab limit to 1: "Editor > Editor Tabs > Tab limit: 1".
  • IdeaVim: In ~/.ideavimrc add this to match the default key maps of this plugin:
nmap     <Space>p <Action>(PinActiveEditorTab)
nmap     <Space>w <Action>(CloseContent)
nmap     <Up>     <Action>(PreviousTab)
nmap     <Down>   <Action>(NextTab)
nnoremap <Left>   :tabmove -1<CR>
nnoremap <Right>  :tabmove +1<CR>
nmap     <F1>     <Action>(GoToTab1)
nmap     <F2>     <Action>(GoToTab2)
nmap     <F3>     <Action>(GoToTab3)
nmap     <F4>     <Action>(GoToTab4)

Inspiration

Contributing

I welcome issues requesting any behavior change. However, please do not submit a PR unless it's for a trivial fix.

License

MIT

About

Manually track a list of bufs and visualize it in the tabline

Topics

Resources

License

Stars

Watchers

Forks

Contributors