Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mihaifm/bufstop

Fast and efficient buffer switching for Vim
https://github.com/mihaifm/bufstop

vim vim-plugin vim-plugins vim-script viml

Last synced: 3 days ago
JSON representation

Fast and efficient buffer switching for Vim

Awesome Lists containing this project

README

        

# Bufstop

If you find yourself frequently switching back and forth between files, and looking for
a faster way to do it, well...your journey has come to an end. Welcome to the **Bufstop** !

**Bufstop** is a plugin for faster buffer switching, built for efficiency and less keystrokes.
It provides no less than 7 ways to display and switch buffers.

If you can think of faster ways to switch files, let me know and I will include them in the plugin.

![image](https://github.com/mihaifm/bufstop/assets/981184/ed719eb5-0fd3-40f2-ae63-083c18e5b844)

## Buffer window with hotkeys

https://github.com/mihaifm/bufstop/assets/981184/21294af7-54de-4c67-b8fb-9779640b6853

The `:Bufstop` command opens a new window at the top/bottom of the screen containing the list of
current buffers, ordered by most recently used. Each buffer has an associated hotkey
displayed besides it. When pressed, the correspoding buffer
is loaded, with the focus remaining in the Bufstop window. This way you can quickly preview
buffers with only 1 keystroke !

The Bufstop window is easily dismissed with the `` key.

There is also a `:BufstopFast` command which opens the Bufstop window in the same way,
but spares you the effort of pressing the `` key : the window closes automatically after
you select a buffer.

**_Tip:_** If you're using the recommended mappings (see below), `b2` will always take you to
the previously opened file (aka *alternate buffer*)

## Preview mode

https://github.com/mihaifm/bufstop/assets/981184/86fea879-67fa-4902-98f6-f5acdafab141

The `:BufstopPreview` command is similar to the `:Bufstop` command, with the notable difference that you can
preview and navigate files by moving **up or down** in the window with `j,k` or arrow keys.
It is a powerful and instant way to check your files.

**_Tip:_** You can still switch files by pressing the hotkeys associated with them.

## Minimal mode inside the command line

https://github.com/mihaifm/bufstop/assets/981184/1d6e450f-851c-48e9-be5f-4bcc6dbd7047

Don't like a pottentially huge file list popping on the screen? Use the `:BufstopMode` command.
Buffers will be displayed in the command line, in the same order: by most recently used.

In this mode, you can only press numbers. Pressing `3` will take you to the 3rd recently used
buffer. However here's __*the catch*__: because the 3rd buffer will now be first in the hierarchy,
it's place will be taken by another buffer.
So pressing `33333....` will __*cycle between the last 3 buffers*__.
Similarly, `4444` will cycle the last 4 buffers, and so on.

Pressing `` will dismiss the mode. There is a `:BufstopModeFast` alternative,
which dismisses the mode once you select a buffer.

**_Tip:_** The first buffer labeled with `1` will always be the current file.

## On the statusline

The `:BufstopStatusline` command works the same way as `:BufstopMode`, but displays the buffers
on the statusline. As before, there is a fast alternative, `:BufstopStatuslineFast` that
will close the mode once you select something.

**_Tip:_** No worries, your old statusline is restored once you exit the mode.

## Extreme speed hotkeys

The previous methods are cool, but they still require a mapping to bring up the buffer list
(typically `b`).
Looking for a faster way? Use the `:BufstopSpeedToggle` command.

It creates the following mappings: `2` opens the previous buffer, `3` to open
the 3rd recently used buffer, and so on.

Using `:BufstopSpeedToggle` again will clear out these mappings.

**_Tip:_** Pressing `,5,5,5...` will cycle the last 5 buffers.

## Ultimate

The previous speed method requires 2 keys to open any arbitrary buffer. Too much? Put this
in your `vimrc`:

let g:BufstopSpeedKeys = ["", "", "", "", "", ""]
let g:BufstopLeader = ""
let g:BufstopAutoSpeedToggle = 1

Yes, you guessed it. __*1 key to open arbitrary buffers*__ !

Once again, pressing `...` will cycle between the last 4 buffers.

**_Tip:_** Already had something mapped to ``? Use `:BufstopSpeedToggle` to switch off
these mappings. Bufstop will attempt to restore your old mapping (given that you didn't use
`noremap`).

## Bonuses

1. As a bonus, this plugin provides __*navigation history for each window*__.
Use the `:BufstopBack` and `:BufstopForward` to navigate this history.

2. The other bonus is the ability to sort the buffers by __*MFU (most frequently
used)*__. Use the `g:BufstopSorting` option to activate this powerful feature.

## Recommended mappings

Hopefully we're not crazy to type in those long command names. You can use the below
mappings or create your own:

map b :Bufstop " get a visual on the buffers
map w :BufstopPreview " switch files by moving inside the window
map a :BufstopModeFast " a command for quick switching
map :BufstopBack
map :BufstopForward
let g:BufstopAutoSpeedToggle = 1 " now I can press ,3,3,3 to cycle the last 3 buffers

## Don't like this plugin?

At least put this in your `vimrc`:

:map b :ls:b

It will display the buffer list and prompt you for a number. Simple, but primitive, especially
when you're dealing with a lot of files.

In addition to this plugin, you can use a fuzzy finder like
[CtrlP](https://github.com/kien/ctrlp.vim), which requires you to type parts of the file name.

## Reference documentation

### Commands:

* `:Bufstop`

Invokes the `Bufstop` window. Inside it, each buffer will have an associated
hotkey that can be used to open the buffer.

In addition, the following key mappings are present in the `Bufstop` window:

d Wipe the selected buffer (close the file)
Open the selected buffer.
Dismiss the Bufstop window
k,j Move up/down to select a buffer.

* `:BufstopFast`

Same as `:Bufstop`, but the window is closed after you select a buffer.

* `:BufstopPreview`

Same as `:Bufstop` but navigating to different rows with k,j or arrow keys will
instantly swtich buffers.

* `:BufstopMode`

Display the most recently used buffers in the command line and enter Bufstop mode.
In this mode you can press only a number coresponding to a buffer, or the `` key
which exits the mode. The number of displayed files can be configured using
the `g:BufstopModeNumFiles` option.

* `:BufstopModeFast`

Same as `:BufstopMode` but exits the mode once a buffer is selected.

* `:BufstopStatusline`

Same as `:BufstopMode` but displays the list in the statusline. The old statusline is
restored once the mode is dismissed.

* `:BufstopStatuslineFast`

Same as `:BufstopStatusline` but exists the mode once a buffer is selected.

* `:BufstopSpeedToggle`

Toggle speed mappings. The defaults are `2` to go to the 2nd recently used buffer,
`3` to go to the 3rd, an so on. These can be configured using the
`g:BufstopSpeedKeys` and `g:BufstopLeader` options.

* `:BufstopBack`

Opens the previous buffer in the navigation history for the current window.

* `:BufstopForward`

Opens the next buffer in the navigation history for the current window.

## Config

* `g:BufstopKeys`

The shortcut keys used to switch buffers. The keys are displayed next to the
buffer names, in the order they appear in this string.
Default: `"1234asfcvzx5qwertyuiopbnm67890ABCEFGHIJKLMNOPQRSTUVZ"`

* `g:BufstopSpeedKeys`

Keys used to create speed mappings. The `g:BufstopLeader` will be appended to
each key to create the mappig.
Default: `["1", "2", "3", "4", "5", "6"]`

* `g:BufstopLeader`

The key that is appended to the speed mappings.
Default: `""`

* `g:BufstopAutoSpeedToggle`

Mount the speed mappings automatically when loading the plugin. Default is 0.

* `g:BufstopSplit`

The split location of the Bufstop window. Valid options are the ones that
influence the `:split` command in Vim: `topleft`, `leftabove`, `rigthbelow`, etc.
Default: `"botright"`

* `g:BufstopSorting`

Controls the way buffers are sorted before being displayed. Valid options are:

"MRU" - sort by most recently used
"MFU" - sort by most frequently used
"none" or "" - disable sorting

Default: `"MRU"`

More config options with `:help Bufstop`

## Customization

You can add symbols/icons next to buffer names by implementing `g:BufstopFileSymbolFunc` in you vimrc.
Example using the vim-devicons plugin:

let g:BufstopFileSymbolFunc = 'MyBufstopFileIcon'
function MyBufstopFileIcon(path)
return WebDevIconsGetFileTypeSymbol(a:path)
endfunction

You can format file names displayed by the plugin by implementing `g:BufstopFileFormatFunc`.
For example you can hide file extensions:

let g:BufstopFileFormatFunc = 'MyBufstopFileFormat'
function! MyBufstopFileFormat(shortname)
return fnamemodify(a:shortname, ':t:r')
endfunction

Enjoy!