Post

Neovim Configuration Fuzzy Selector

nvims nvims
Example Nvims Fuzzy Selector Usage

Introduction

The two primary features of the Lazyman project are the lazyman command and the nvims shell function. The lazyman command provides a menu interface and command line options to install, initialize, and manage multiple Neovim configurations. The nvims shell function dynamically generates a fuzzy searchable menu of Neovim configurations from which to select. The selected configurations can be opened in Neovim, removed, or a configuration information document can be viewed.

If selected for opening Neovim, the configuration selection is “sticky”. Subsequent invocations of vi will use the previously selected Neovim configuration until another configuration is selected with nvims.

Help for the nvims and neovides shell functions can be found in the nvims man page with man nvims, with the command nvims -U, or in Neovim using the Lazyman configuration with :h Nvims.

The nvims fuzzy selector

The lazyman installation and configuration automatically configures convenience aliases and shell functions for Lazyman installed Neovim configurations. One of these is the nvims shell function which dynamically creates a fuzzy searchable menu of installed Neovim configurations and launches Neovim with the selected Lazyman Neovim configuration.

See ~/.config/nvim-Lazyman/.lazymanrc.

Similarly, a neovides shell function can be used to select a Neovim configuration for use with the Neovim GUI neovide.

Both the nvims shell function and neovides shell function accept a -R flag which indicates removal of the selected Neovim configuration. Also supported is the -C filter option to nvims and neovides which specifies a filter string to match when generating the list of Neovim configurations to search and select.

The fuzzy searchable/selectable menu of Neovim configurations can also be shown with the command lazyman -S. Note also that both the nvims shell function and the lazyman -S command can accept additional filename arguments which are then passed to Neovim. For example, to edit /tmp/foo.lua with a Neovim configuration selected from the nvims menu:

1
nvims /tmp/foo.lua

Execute nvims directly at the shell prompt or by using the convenience key binding ctrl-n.

Similarly, if neovide is found in the execution PATH then a fuzzy selectable menu is provided with the neovides shell function and convenience key binding of ctrl-N to bring up that menu.

The following command line options are available with nvims and neovides:

-c command
specifies an Ex command to be executed after the first file has been read
-C filter
specifies a filter to use when generating the list of configurations to select from
-I
indicates display of the selected Neovim configuration information document
-R
indicates removal of the selected Neovim configurations
-S file
Executes Vimscript or Lua in file after the first file has been read. If no -S argument is provided then ~/.config/nvim-Lazyman/overrides.lua is used if not empty.
-U
displays a usage message and exits

Without arguments nvims and neovides generate a fuzzy search and selectable menu of all Lazyman installed Neovim configurations. Neovim or neovide will be opened using the selected configuration.

Example nvims and neovides usage

nvims
presents a fuzzy searchable and selectable menu of Neovim configurations and opens Neovim using the selected configuration
neovides
presents a fuzzy searchable and selectable menu of Neovim configurations and opens Neovide using the selected configuration
nvims -R
presents a fuzzy searchable and selectable menu of Neovim configurations and removes the selected Neovim configuration
nvims -C astro foo.lua
presents a fuzzy searchable and selectable menu of Neovim configurations with names containing the case insensitive string ‘astro’ and opens the file foo.lua with Neovim using the selected configuration

The nvims shell function, when executed, presents a fuzzy searchable menu of the lazyman installed Neovim configurations. The lazyman installed Neovim configurations are maintained in the file ~/.config/nvim-Lazyman/.nvimdirs. Entries in this file are what nvims uses for its fuzzy selection menu. When Neovim configurations are installed or removed with lazyman this file is updated accordingly.

Note also that a convenience key binding has been created to launch nvims with ctrl-n.

Similarly, if neovide is found in the execution PATH then a fuzzy selectable menu is provided with the neovides shell function and convenience key binding of ctrl-N to bring up that menu.

The nvims Neovim configuration switching shell function was created by Elijah Manor. He created an excellent Neovim Config Switcher video in which he provides details on use and customization of the nvims shell function.

Lazyman has incorporated and adapted the nvims shell function for use with the Lazyman installed Neovim configurations. The nvims shell function is automatically configured during lazyman installation.

The .lazymanrc file also creates aliases for ls, less, and others including a tldrf alias that allows fuzzy searching and selecting from the list of cheatsheets supported by tldr. Try out the tldrf command to quickly and easily display documentation for thousands of commands. The idea for the tldrf alias came from another video by Elijah Manor.

Source listing

View the .lazymanrc shell aliases and nvims function on Github.

This post is licensed under CC BY 4.0 by the author.