Pin buffers for quick navigation.
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.
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.
- 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) ifvim.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:
- mini.icons: Display file type icon next to buf name. Use a Nerd Font.
- mini.bufremove: Preserve window layout when removing bufs.
- vim-lastplace: Remember the cursor location in visited bufs.
- Be a fully-fledged tabline plugin like bufferline.nvim.
- Neovim >= 0.11.0
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.
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",
})Please refer to the help file: bufpin.txt.
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
~/.ideavimrcadd 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)I welcome issues requesting any behavior change. However, please do not submit a PR unless it's for a trivial fix.
