sponsor Vim development Vim logo Vim Book Ad

Zeef : Interactively filter a list of items

 script karma  Rating 9/3, Downloaded by 297  Comments, bugs, improvements  Vim wiki

created by
Lifepillar
 
script type
utility
 
description
Zeef is a 100% Vim script. minimalist, pure autoload, dynamic interactive filter for a list of items. Think of it as a wise man's CtrlP. It is used by invoking zeef#open(). Zeef does not define any command or mapping. The arguments of the function are:

1. A list of items;
2. The name of a callback function;
3. The text for the command line prompt.

(The function accepts an optional fourth argument to set up custom key mappings: see `:help zeef` for the details).

Try this "zeef":

    fun Callback(result)
      echo a:result
    endf

    call zeef#open(['January', 'July', 'Lily', 'Lyric', 'Nucleus'], 'Callback', 'Choose')

Start typing to filter the list. Press Enter to invoke the callback with the selected item(s) (multiple selections are possible—see below). Press Esc to cancel. The following is the complete list of keys you can use when the Zeef buffer is open (these can be customized with g:zeef_keymap):

CTRL-K or up arrow: move up one line;
CTRL-J or down arrow: move down one line;
left and right arrows: scroll horizontally;
CTRL-B, CTRL-F, CTRL-D, CTRL-U, CTRL-E, CTRL-Y: usual movements;
CTRL-L: clear the prompt;
CTRL-G: clear the prompt and deselect all items;
CTRL-Z: select/deselect the current line;
CTRL-A: select all currently filtered lines;
CTRL-R: deselect all currently filtered lines;
Esc, CTRL-C: close Zeef without performing any action;
Enter: accept the current choice;
CTRL-S, CTRL-V, CTRL-T: like Enter, but also open a split, vertical split or tab.

How does Zeef differ from the several similar plugins already out there, you ask? The implementation is likely *the simplest possible*: as you type, :global is used to remove the lines that do not match what you are typing. When you press backspace, :undo is used to restore the previous state. Yes, the core of this plugin is based on just those two Vim commands. It works surprisingly well, unless your list is huge (hundreds of thousands of lines).

What can you do with Zeef? Whatever you want! Zeef is not bloated with features that you will never use: it is for people who wish to implement their own functionality with minimal help. That said, Zeef does come with a few "sample applications":

- a buffer switcher;
- a path filter;
- a quickfix/location list filter;
- a color scheme selector;
- a buffer tag chooser.

Use the source code as the authoritative reference. It's not that complicated. And don't forget to read the full (albeit short) documentation: see :help zeef.txt.

Ah, before you ask: the answer is no. Zeef does not perform fuzzy search, approximate search, match rankings, or other esoteric stuff. All that is out of the scope of this project. Those are features that are well covered by other plugins, after all.

LICENSE

Copyright ©2020 Lifepillar

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
install details
mkdir -p ~/.vim/pack/plugins/start
git clone https://github.com/lifepillar/vim-zeef.git ~/.vim/pack/plugins/start/zeef
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-zeef-v1.0.1.tar.gz 1.0.1 2020-11-16 7.4 Lifepillar Allows overriding mappings for a single call of zeef#open(). Allows (de)selecting all filtered items at once. Shows the number of selected items in the status line. Adds zeef#result() and zeef#keypressed() to get the list of selected items and the last key pressed, respectively (useful in callbacks in some cases). Bug fixes in parsing tags and highlighting. Improved documentation and compatibility with older Vim. Licensed under MIT.
vim-zeef-1.0.0.tar.gz 1.0.0 2020-10-08 7.4 Lifepillar Initial upload
ip used for rating: 3.137.218.230

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github