Ecosyste.ms: Awesome

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

https://github.com/rlane/pounce.nvim

Incremental fuzzy search motion plugin for Neovim
https://github.com/rlane/pounce.nvim

Last synced: about 2 months ago
JSON representation

Incremental fuzzy search motion plugin for Neovim

Lists

README

        

# pounce.nvim

Pounce is a motion plugin similar to [EasyMotion][1], [Sneak][2], [Hop][3], and
[Lightspeed][4]. It's based on incremental fuzzy search. Here's a demo:

![demo](.assets/demo.gif)

The demo shows searching for the word "ht_mask" by typing "s" to activate
Pounce, "htm" to refine the search, and then "J" to select the match.

[1]: https://github.com/easymotion/vim-easymotion
[2]: https://github.com/justinmk/vim-sneak
[3]: https://github.com/phaazon/hop.nvim
[4]: https://github.com/ggandor/lightspeed.nvim

## Installation

Using vim-plug:

```
Plug 'rlane/pounce.nvim'
```

## Usage

The `:Pounce` command starts the motion. Type the character at the destination
and Pounce will highlight all matches on screen. Next, refine the matches by
typing more characters (in order) that are present after the destination. The
first letter of the match will be replaced with an uppercase "accept key". You
can hit that key to jump to the match, or continue refining the search. Enter
accepts the best match (highlighted in blue). Escape cancels the motion and
leaves the cursor at its previous position.

You can also use `:Pounce ` to initialize the search with ``. You
can directly hit the accept key to jump to that match or continue refining as
normal. You can use this with `` to initialize the search with the
contents of a register, For example `/` will initialize the search with
the last search pattern you used in `/`. You can also consider using ``
mappings or lua callbacks with `vim.fn.expand`. For these use cases the
commands `PounceReg ` and `PounceExpand ` are defined.

The `:PounceRepeat` command works the same way but is initialized with the
input from the previous Pounce command.

No mappings are created by default. Here's a suggestion:

```vim
nmap s Pounce
nmap S PounceRepeat
xmap s Pounce
omap gs Pounce " 's' is used by vim-surround
nmap S :Pounce / " note: if you want to use you cannot use
```

You can also use the lua api directly:

```lua
local map = vim.keymap.set
map("n", "s", function() require'pounce'.pounce { } end)
map("n", "S", function() require'pounce'.pounce { do_repeat = true } end)
map("x", "s", function() require'pounce'.pounce { } end)
map("o", "gs", function() require'pounce'.pounce { } end)
map("n", "S", function() require'pounce'.pounce { input = {reg="/"} } end)
```

The `pounce` function takes a table as its argument, you can use any keys that
`setup` accepts, as well as:

```lua
require'pounce'.pounce{
do_repeat = true|false -- to reuse the last pounce search
input = string|table -- a string to initialize the input, or a table:
input = {
reg = string -- the name of a vim register to use as the input (:h registers)
expand = string -- an expression passed to vim.fn.expand (:h expand())
}
}
```

Configuration is done with the `setup` function. It's optional to call `setup`.
Here are the defaults:

```lua
require'pounce'.setup{
accept_keys = "JFKDLSAHGNUVRBYTMICEOXWPQZ",
accept_best_key = "",
multi_window = true,
debug = false,
}
```

Note that `accept_keys` allows you to configure the order in which accept keys
display – closest proximity match gets the first letter in the `accept_keys`
string. Users of alternative keyboard layouts may wish to amend that string.
Colemak DHm might start with `NTESIROA...` for example.

Below are listed some example extra commands you can use:

```vim
PounceReg / " Pounce with last search pattern
PounceReg 0 " Pounce with last yank
PounceReg \" " Pounce with last d/c/y
PounceReg . " Pounce with last inserted text
\"zyPounceReg z " From visual mode: Pounce using the selection as the input
PounceExpand " Pounce with the current word
PounceExpand % " Pounce with the current filename
```

## Related Work

There are quite a few plugins in this space. Here are some alternatives to
Pounce:

- https://github.com/easymotion/vim-easymotion
- https://github.com/justinmk/vim-sneak
- https://github.com/phaazon/hop.nvim
- https://github.com/ggandor/lightspeed.nvim
- https://github.com/yuki-yano/fuzzy-motion.vim
- https://github.com/hrsh7th/vim-searchx