Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/gw31415/fzyselect.vim

The simplest fuzzy selector plugin of Vim
https://github.com/gw31415/fzyselect.vim

fuzzy neovim vim

Last synced: 10 days ago
JSON representation

The simplest fuzzy selector plugin of Vim

Awesome Lists containing this project

README

        

# fzyselect.vim
**fzyselect.vim** is a simple fuzzy selector plugin of Vim.

https://user-images.githubusercontent.com/24710985/188317718-5a136fd2-7f0f-4115-bb8f-cb34fd9605ec.mov

## Introduction
The `vim.ui.select` implemented in Neovim is simple and extensible.
There are also several well-designed extension plugins based on it
(e.g. [dressing.nvim](https://github.com/stevearc/dressing.nvim)).

This plugin is one such extensions. As a feature, it uses a built-in `matchfuzzypos`
function to speed up the search process. Also, for the minimalists (or following the UNIX philosophy),
it has few extra functions, keymaps and commands as possible.

You can use this plugin in Vim as well as Neovim. Except exporting code for Lua,
the all of this plugin is written in only Vim scripts (not Vim9 scripts).

## Installation

[Plug.vim](https://github.com/junegunn/vim-plug)
```vim
Plug 'gw31415/fzyselect.vim'
```

[dein.vim](https://github.com/Shougo/dein.vim)
```vim
call dein#add('gw31415/fzyselect.vim')
```

[packer.nvim](https://github.com/wbthomason/packer.nvim)
```lua
use 'gw31415/fzyselect.vim'
```

### Key mappings
No default keymaps are provided.

#### Vim Scripts
```vim
fu! s:fzy_keymap()
nmap i (fzyselect-fzy)
nmap (fzyselect-retu)
nmap clo
endfu
au FileType fzyselect cal fzy_keymap()
```

#### Lua
```lua
vim.api.nvim_create_autocmd('FileType', {
pattern = 'fzyselect',
callback = function ()
vim.keymap.set('n', 'i','(fzyselect-fzy)', { buffer = true })
vim.keymap.set('n', '','(fzyselect-retu)', { buffer = true })
vim.keymap.set('n', '','clo', { buffer = true })
end
})
```

### For Neovim users: `vim.ui.select`
If you want to replace `vim.ui.select` with this plugin's,
you can directly assign the function `require 'fzyselect'.start`.

```lua
vim.ui.select = require 'fzyselect'.start
```

## How to use
Only one function `fzyselect#start` is provided
(two if you includes `require 'fzyselect'.start` exported for Lua).

You can use similar to `vim.ui.select`.
Please see [this document](https://neovim.io/doc/user/lua.html#vim.ui.select()).

### Vim Scripts
```vim
cal fzyselect#start(['apple', 'banana', 'chocolate'],
\ {}, {i->append('.', i)})
```

### Lua
```lua
require 'fzyselect'.start({'apple', 'banana', 'chocolate'}, {},
function(i)
vim.fn.append('.', i)
end)
```

On the split window that appears then you can use the usual keymaps you set up.
To operate fuzzy selecting, you need to set up two keymaps:

| Key | Usage |
:------------------------ | :-------------------
| `(fzyselect-fzy)` | Launch fuzzy search. |
| `(fzyselect-retu)` | Select the item. |

## Configuration Example
### Lines
Fuzzy search for lines of the current buffer.

```vim
nn gl cal fzyselect#start(getline(1, '$'), #{prompt:'Fuzzy search'}, {_,i->i==v:null?v:null:cursor(i, 0)})
```

image

### Files
Fuzzy search for files of the working directory.

```vim
fu! s:glob(path)
let li = []
for f in readdir(a:path)
let p = a:path .. '/' .. f
if isdirectory(p)
cal extend(li, s:glob(p))
else
cal add(li, p)
en
endfo
return li
endfu
fu! s:edit(path) abort
if a:path != v:null
exe 'e ' .. a:path
en
endfu
nn cal fzyselect#start(glob('.'), {}, {p->edit(p)})
```

image

### Buffers
Fuzzy switcher of buffers.

```vim
fu! s:buffer(i) abort
if a:i != v:null
exe 'b ' .. a:i
en
endfu
nn B cal fzyselect#start(
\ filter(range(1, bufnr('$')), 'buflisted(v:val)'),
\ #{prompt:'Select buffer',format_item:{i->split(execute('ls!'), "\n")[i-1]}},
\ {li->buffer(li)})
```

image