mini.pick

### Pick anything See more details in [Features](#features) and [Documentation](../doc/mini-pick.txt). --- > [!NOTE] > This was previously hosted at a personal `echasnovski` GitHub account. It was transferred to a dedicated organization to improve long term project stability. See more details [here](https://github.com/nvim-mini/mini.nvim/discussions/1970). ⦿ This is a part of [mini.nvim](https://nvim-mini.org/mini.nvim) library. Please use [this link](https://nvim-mini.org/mini.nvim/readmes/mini-pick) if you want to mention this module. ⦿ All contributions (issues, pull requests, discussions, etc.) are done inside of 'mini.nvim'. ⦿ See [whole library documentation](https://nvim-mini.org/mini.nvim/doc/mini-nvim) to learn about general design principles, disable/configuration recipes, and more. ⦿ See [MiniMax](https://nvim-mini.org/MiniMax) for a full config example that uses this module. --- If you want to help this project grow but don't know where to start, check out [contributing guides of 'mini.nvim'](https://nvim-mini.org/mini.nvim/CONTRIBUTING) or leave a Github star for 'mini.nvim' project and/or any its standalone Git repositories. ## Demo https://github.com/nvim-mini/mini.nvim/assets/24854248/65849d1e-3f96-4085-a4cf-f9962cfdbdfd ## Features - Single window general purpose interface for picking element from any array. - On demand toggleable preview and info views. - Interactive query matching (filter+sort) with fast non-blocking default which does fuzzy matching and allows other modes. - Built-in pickers: - Files. - Pattern match (for fixed pattern or with live feedback; both allow file filtering via glob patterns). - Buffers. - Help tags. - CLI output. - Resume latest picker. - `:Pick` command to work with extensible `MiniPick.registry`. - `vim.ui.select()` implementation. To adjust, use `MiniPick.ui_select()` or save-restore `vim.ui.select` manually after calling `MiniPick.setup()`. - Rich and customizable built-in actions when picker is active: - Manually change currently focused item. - Scroll vertically and horizontally. - Toggle preview or info view. - Mark/unmark items to choose later. - Refine current matches (make them part of a new picker). - And many more. - Minimal yet flexible source specification with: - Items (array, callable, or manually set later). - Source name. - Working directory. - Matching algorithm. - Way matches are shown in main window. - Item preview. - "On choice" action for current and marked items. - Custom actions/keys can be configured globally, per buffer, or per picker. - Out of the box support for 'ignorecase' and 'smartcase'. - Match caching to increase responsiveness on repeated prompts. Notes: - For more pickers see ['mini.extra'](https://nvim-mini.org/mini.nvim/readmes/mini-extra). - CLI tools are called only with basic arguments needed to get items. To customize the output, use their respective configuration approaches. Here are some examples of where to start: - [ripgrep](https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file) - [fd](https://github.com/sharkdp/fd#excluding-specific-files-or-directories) - [git](https://git-scm.com/docs/gitignore) For more information see these parts of help: - `:h MiniPick-overview` - `:h MiniPick-source` - `:h MiniPick-actions` - `:h MiniPick-examples` - `:h MiniPick.builtin` - `:h MiniPick-in-other-plugins` (for plugin authors) ## Dependencies For full experience needs (still works without any of suggestions): - Enabled ['mini.icons'](https://nvim-mini.org/mini.nvim/readmes/mini-icons) module for icons near the items representing actual paths. Can fall back to using [nvim-tree/nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) plugin. - Executable [BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) CLI tool for faster file and pattern search on disk. ## Overview General idea is to take array of objects, display them with interactive filter/sort/navigate/preview, and allow to choose one or more items. ### How to start a picker - Use `MiniPick.start()` with `opts.source` defining source. Example: `MiniPick.start({ source = { items = vim.fn.readdir('.') } })` - Use any of `MiniPick.builtin` pickers directly. Example: `MiniPick.builtin.files({ tool = 'git' })` - Use `:Pick` command which uses customizable pickers from `MiniPick.registry`. Example: `:Pick files tool='git'` ### User interface UI consists from a single window capable of displaying three different views: - "Main" - where current query matches are shown. - "Preview" - preview of current item (toggle with ``). - "Info" - general info about picker and its state (toggle with ``). Current prompt is displayed at the top left of the window border with vertical line indicating caret (current input position). Bottom part of window border displays extra visual feedback: - Left part is a picker name. - Right part contains information in the format: ` | | / ` When picker is busy (like if there are no items yet set or matching is active) window border changes color to be `MiniPickBorderBusy` after `config.delay.busy` milliseconds of idle time. ### Life cycle - Type characters to filter and sort matches. It uses `MiniPick.default_match()` with `query` being an array of pressed characters. Overview of how it matches: - If query starts with `'`, the match is exact. - If query starts with `^`, the match is exact at start. - If query ends with `$`, the match is exact at end. - If query starts with `*`, the match is forced to be fuzzy. - Otherwise match is fuzzy. - Sorting is done to first minimize match width and then match start. Nothing more: no favoring certain places in string, etc. - Type special keys to perform actions. Here are some basic ones: - `` / `` moves down; `` / `` moves up. - `` / `` moves prompt caret left / right. - `` toggles information window with all available mappings. - `` toggles preview. - `` / `` toggles current / all item(s) as (un)marked. - `` / `` makes all matches or marked items as new picker. - `` / `` chooses current/marked item(s). - `` / `` stops picker. ## Installation This plugin can be installed as part of 'mini.nvim' library (**recommended**) or as a standalone Git repository. There are two branches to install from: - `main` (default, **recommended**) will have latest development version of plugin. All changes since last stable release should be perceived as being in beta testing phase (meaning they already passed alpha-testing and are moderately settled). - `stable` will be updated only upon releases with code tested during public beta-testing phase in `main` branch. Here are code snippets for some common installation methods (use only one):
(Recommended) With vim.pack (on Neovim 0.12 and newer) **Full library** Follow ['mini.nvim' installation](https://nvim-mini.org/mini.nvim#installation). **Standalone plugin** Main branch: ```lua vim.pack.add({ 'https://github.com/nvim-mini/mini.pick' }) ``` Stable branch: ```lua vim.pack.add({ { src = 'https://github.com/nvim-mini/mini.pick', version = 'stable' }, }) ```
With mini.deps (before Neovim 0.12) **Full library** Follow [recommended 'mini.deps' installation](https://nvim-mini.org/mini.nvim/readmes/mini-deps#installation). **Standalone plugin**: Main branch: ```lua add('nvim-mini/mini.pick') ``` Stable branch: ```lua add({ source = 'nvim-mini/mini.pick', checkout = 'stable' }) ```
With folke/lazy.nvim **Full library** Follow ['mini.nvim' installation](https://nvim-mini.org/mini.nvim#installation). **Standalone plugin** Main branch: ```lua { 'nvim-mini/mini.pick', version = false }, ``` Stable branch: ```lua { 'nvim-mini/mini.pick', version = '*' }, ```
**Important**: don't forget to call `require('mini.pick').setup()` to enable its functionality. **Note**: if you are on Windows, there might be problems with too long file paths (like `error: unable to create file : Filename too long`). Try doing one of the following: - Enable corresponding git global config value: `git config --system core.longpaths true`. Then try to reinstall. - Install plugin in other place with shorter path. ## Default config ```lua -- No need to copy this inside `setup()`. Will be used automatically. { -- Delays (in ms; should be at least 1) delay = { -- Delay between forcing asynchronous behavior async = 10, -- Delay between computation start and visual feedback about it busy = 50, }, -- Keys for performing actions. See `:h MiniPick-actions`. mappings = { caret_left = '', caret_right = '', choose = '', choose_in_split = '', choose_in_tabpage = '', choose_in_vsplit = '', choose_marked = '', delete_char = '', delete_char_right = '', delete_left = '', delete_word = '', mark = '', mark_all = '', move_down = '', move_start = '', move_up = '', paste = '', refine = '', refine_marked = '', scroll_down = '', scroll_left = '', scroll_right = '', scroll_up = '', stop = '', toggle_info = '', toggle_preview = '', }, -- General options options = { -- Whether to show content from bottom to top content_from_bottom = false, -- Whether to cache matches (more speed and memory on repeated prompts) use_cache = false, }, -- Source definition. See `:h MiniPick-source`. source = { items = nil, name = nil, cwd = nil, match = nil, show = nil, preview = nil, choose = nil, choose_marked = nil, }, -- Window related options window = { -- Float window config (table or callable returning it) config = nil, -- String to use as caret in prompt prompt_caret = '▏', -- String to use as prefix in prompt prompt_prefix = '> ', }, } ``` ## Similar plugins - [nvim-telescope/telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) - [ibhagwan/fzf-lua](https://github.com/ibhagwan/fzf-lua)