Important
This is an executable Markdown file, an experiment of merging documentation and code together. A tool for running the code is under development. The focus of this document is to figure a syntax that does not get in the way of the code.
Original version from elijahmanor's gist
Easily manage and switch between multiple Neovim configurations using a fuzzy finder.
The script uses NVIM_APPNAME
to switch between configs which are stored in ~/.config/nvim-flavours/
.
You can add new configs by placing them in the configs directory and the script will automatically include them in the selection list.
nvims [FILE, ...FILES]
: Select and launch a Neovim confignvims --help
: Show usage and current settings
Ctrl+N
: Quick access tonvims
See ~/.config/nvim-flavours/
#!/bin/bash
The nvims
command will check for NeoVim flavors in the $NVIM_FLAVOURS_DIR
directory,
which defaults to $HOME/.config/nvim-flavours
if not set.
# Set NVIM_FLAVOURS_DIR only if it's not already defined
if [ -z "${NVIM_FLAVOURS_DIR}" ]; then
export NVIM_FLAVOURS_DIR="$HOME/.config/nvim-flavours"
fi
We cache the list of flavors in the NVIM_FLAVOURS
array, so if you add a new flavor, you'll need to restart the shell.
export NVIM_FLAVOURS=("default" $(ls $NVIM_FLAVOURS_DIR))
These are the current values of those variables:
echo "NVIM_FLAVOURS_DIR: $NVIM_FLAVOURS_DIR"
echo "NVIM_FLAVOURS: ${NVIM_FLAVOURS[@]}"
__nvims_config_dir() {
if [[ -z $1 || $1 == "default" ]]; then
echo ""
else
echo "${NVIM_FLAVOURS_DIR}/$1"
fi
}
Now hre's the real function!
function nvims() {
First let's check if the user has requested to see this help message.
if ! @help "$*"; then
Then we use fzf
to show a nice fuzzy finder with the list of flavors for you to pick from.
config=$(printf "%s\n" "${NVIM_FLAVOURS[@]}" | fzf --prompt=" Neovim Config " --height=~50% --layout=reverse --border --exit-0)
If you change your mind and don't select anything, that's fine, we'll just exit.
if [[ -z $config ]]; then
echo "Nothing selected"
return 0
fi
If you picked one, we set the $NVIM_APPNAME
env variable to the selected flavor and launch Neovim 🚀!
NVIM_APPNAME=$(__nvims_config_dir $config) nvim "$@"
fi
}
Finally, we bind the nvims
command to Ctrl+N
in the shell.
bindkey -s '^n' "nvims\n"