• Stars
    star
    246
  • Rank 164,726 (Top 4 %)
  • Language
    Lua
  • License
    MIT License
  • Created over 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Neovim plugin for locking a buffer to a window

stickybuf.nvim

Neovim plugin for locking a buffer to a window

Have you ever accidentally opened a file into your file explorer or quickfix window?

stickybuf.mp4

This may eventually be addressed within vim itself, but until then we can provide a solution with plugins. Stickybuf allows you to pin a window to a specific buffer, buftype, or filetype. Anything that opens a non-matching buffer in that window will be reverted and re-routed to the nearest available window.

Requirements

  • Neovim 0.8+

Installation

stickybuf.nvim supports all the usual plugin managers

lazy.nvim
{
  'stevearc/stickybuf.nvim',
  opts = {},
}
Packer
require('packer').startup(function()
    use {
      'stevearc/stickybuf.nvim',
      config = function() require('stickybuf').setup() end
    }
end)
Paq
require "paq" {
    {'stevearc/stickybuf.nvim'};
}
vim-plug
Plug 'stevearc/stickybuf.nvim'
dein
call dein#add('stevearc/stickybuf.nvim')
Pathogen
git clone --depth=1 https://github.com/stevearc/stickybuf.nvim.git ~/.vim/bundle/
Neovim native package
git clone --depth=1 https://github.com/stevearc/stickybuf.nvim.git \
  "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/stickybuf/start/stickybuf.nvim

Quick start

Add the following to your init.lua

require("stickybuf").setup()

Commands

Command Description
PinBuffer[!] Pin the current buffer to the current window
PinBuftype[!] Pin the buffer in the current window, but allow other buffers with the same buftype
PinFiletype[!] Pin the buffer in the current window, but allow other buffers with the same filetype
Unpin Remove pinning for the current window

API

pin(winid, opts)

pin(winid, opts)
Pin the buffer in the specified window

Param Type Desc
winid nil|integer
opts nil|table
allow nil|fun(bufnr: integer): boolean Return true to allow switching to the buffer
allow_type nil|"bufnr"|"buftype"|"filetype" Allow switching to buffers with a matching value
restore_callback nil|fun(winid: integer) Called after a buffer is restored into the pinned window

Note:

You cannot specify both 'allow' and 'allow_type'

unpin(winid)

unpin(winid)
Remove any pinning logic for the window

Param Type Desc
winid nil|integer

is_pinned(winid)

is_pinned(winid): boolean

Param Type Desc
winid nil|integer

setup(opts)

setup(opts)

Param Type Desc
opts nil|table

should_auto_pin(bufnr)

should_auto_pin(bufnr): nil|"bufnr"|"buftype"|"filetype"
The default function for config.get_auto_pin

Param Type Desc
bufnr integer

Configuration

require("stickybuf").setup({
  -- This function is run on BufEnter to determine pinning should be activated
  get_auto_pin = function(bufnr)
    -- You can return "bufnr", "buftype", "filetype", or a custom function to set how the window will be pinned
    -- The function below encompasses the default logic. Inspect the source to see what it does.
    return require("stickybuf").should_auto_pin(bufnr)
  end
})

You can also use autocmd to pin buffers conditionally

vim.api.nvim_create_autocmd("BufEnter", {
  desc = "Pin the buffer to any window that is fixed width or height",
  callback = function(args)
    local stickybuf = require("stickybuf")
    if not stickybuf.is_pinned() and (vim.wo.winfixwidth or vim.wo.winfixheight) then
      stickybuf.pin()
    end
  end
})

Plugin support

Stickybuf provides built-in support for:

If there is another project that you would like to add out-of-the-box support for, submit a pull request, it's likely you'd only need to update the builtin_supported_filetypes variable in the main source file

How does it work?

Since stickybuf is compensating for missing behavior in vim itself, the implementation is necessarily something of a hack. When a buffer is pinned, its information is stored on the current window in window-local variables. Stickybuf registers a callback on BufEnter that examines the current window and, if that window is pinned, restores the previous buffer and opens the new buffer in an unpinned window.

Since stickybuf relies on being able to restore the pinned buffer after it is hidden, it overrides the bufhidden option of pinned buffers and only cleans up the buffer after a delay. The delay provides enough time to make sure that the buffer isn't going to be restored to the pinned window.

Warning: If you are using any plugin or functionality that relies upon bufhidden, particularly if it relies on bufhidden to trigger BufUnload, BufDelete, or BufWipeout immediately, stickybuf could cause issues. See #1 for a case where this happens with Neogit.

More Repositories

1

oil.nvim

Neovim file explorer: edit your filesystem like a buffer
Lua
3,907
star
2

conform.nvim

Lightweight yet powerful formatter plugin for Neovim
Lua
3,073
star
3

dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
Lua
1,844
star
4

aerial.nvim

Neovim plugin for a code outline window
Lua
1,711
star
5

overseer.nvim

A task runner and job management plugin for Neovim
Lua
1,193
star
6

pypicloud

S3-backed pypi server implementation
Python
505
star
7

vim-arduino

Vim plugin for compiling and uploading arduino sketches
Vim Script
345
star
8

quicker.nvim

Improved UI and workflow for the Neovim quickfix
Lua
321
star
9

resession.nvim

A replacement for mksession with a better API
Lua
226
star
10

gkeep.nvim

Google Keep integration for Neovim
Python
193
star
11

dql

A SQL-ish language for DynamoDB
Python
149
star
12

flywheel

Object mapper for Amazon's DynamoDB
Python
128
star
13

profile.nvim

lua profiler for nvim
Lua
126
star
14

qf_helper.nvim

A collection of improvements for the quickfix buffer
Lua
97
star
15

pypicloud-docker

Docker image for pypicloud
Shell
86
star
16

dotfiles

Lua
57
star
17

godot_parser

Python library for parsing Godot scene files
Python
54
star
18

pair-ls

Editor-agnostic remote pair programming
TypeScript
28
star
19

three.nvim

Neovim plugin for working with buffers, windows, and tabs
Lua
21
star
20

nvim-typecheck-action

Github action for typechecking a neovim plugin
Lua
17
star
21

pair-ls.nvim

Neovim plugin for pair-ls
Lua
14
star
22

dynamo3

Python 3 compatible library for DynamoDB
Python
13
star
23

gitstack

A utility for stacking branches and github pull requests
Python
12
star
24

pyramid_webpack

Pyramid extension for managing assets with Webpack
Python
10
star
25

vim-vscode-snippets

A collection of vscode snippets for vim
Python
9
star
26

nvim_doc_tools

Python scripts for Neovim documentation generation
Python
7
star
27

pyramid_duh

Utilities that you'll want for nearly every pyramid app
Python
6
star
28

Battlecode-Server-Tester

Distributed testing tool for the MIT Battlecode competition
Java
3
star
29

parseargs

Bash utility for parsing commandline arguments
Shell
2
star
30

pike

Asset pipeline and make tool
Go
2
star
31

pair-ls-vscode

VS Code extension for pair-ls
TypeScript
2
star
32

eat_your_vegetables

An organizational wrapper around celery
Python
2
star
33

bluepill

A command line utility for working inside docker containers
Python
2
star
34

pore

Command line full-text search
Rust
2
star
35

flow-coverage.nvim

Neovim plugin to display flow type coverage information
Lua
2
star
36

stevearc

1
star
37

stevetags

Little website for tagging Dropbox files
Python
1
star