Personal Neovim configuration.
I have rewritten my Neovim configuration multiple times which has been a great learning exercise and I will likely continue to do so in the future. This iteration is not based on any specific distro but is a culmination of my learnings around how to manage the configuration / plugins.
This configuration is uses lazy.nvim as the package / plugin manager.
The leader
key is defined as the spacebar.
If you don't have an existing Neovim configuration then the simplest way to install is:
brew install nvim
git clone https://github.com/tim-kuntz/config.nvim.git ~/.config/nvim
nvim
If you are like me and your ~/.config
($XDG_CONFIG_HOME) directory already has one or
more Neovim configurations then I would suggest the following installation for trial
purposes.
git clone https://github.com/tim-kuntz/config.nvim.git ~/.config/nvim-trial
NVIM_APPNAME=nvim-trial nvim
Because I like to experiment with different configurations and I don't want to mess with my stable / current configuration, I have taken the following approach based on this gist from Elijah Manor.
-
When adding new Neovim configurations, use the naming convention
nvim-<name>
; for example,nvim-trial
ornvim-rails
. -
Add the following script to your shell startup. I use oh my zsh so have added it to
~/.oh-my-zsh/custom/alias.zsh
.
function nvims() {
# add new nvim configuration under ~/.config/nvim-*
items=("default")
for dir in ~/.config/nvim-*/; do
if [ -d "$dir" ]; then
alias $(basename $dir)="NVIM_APPNAME=$(basename $dir) nvim"
items+=("$(basename $dir)")
fi
done
config=$(printf "%s\n" "${items[@]}" | fzf --prompt=" Neovim Config " --height=~50% --layout=reverse --border --exit-0)
if [[ -z $config ]]; then
echo "Nothing selected"
return 0
elif [[ $config == "default" ]]; then
config=""
else
fi
NVIM_APPNAME=$config nvim $@
}
bindkey -s ^a "nvims\n"
Now when you run the command nvims
or press Ctrl+a
, you will get a list of
your installed configurations to start Neovim from. Pretty nifty!
- On first starting Neovim with the configuration,
lazy.nvim
will install if needed, then download required plugins. - (Optional) Open the Lazy plugin window by pressing
<leader>l
. You can pressU
to ensure all plugins are updated and run a check withC
. - Use the
which-key
popup when pressing the leader key (space) to get an idea of all the custom options.
TODO - review any dependencies on external programs; ripgrep
, fzf
, ...
For LSP support, mason.nvim is included. You can manage the installation of language servers
by running the vim command :Mason
.
Understanding the directory / file layout will assist in making changes.
init.lua
Contains the lazy.nvim
bootstrapping only.
plugin
Anything I want to run at boot; Vim settings, creation of global helper functions, autocmds, and key mappings.
after/ftplugin
Configuration specific to file types. It is in the after
directory to allow for overriding default settings; see :help ftplugins
.
lua/custom/plugins/*.lua
These Lua files should contain the lazy.nvim
plugin spec only and configuration should be in a separate file (see next directory).
lua/custom/*.lua
Any Lua files in this directory should correspond to a plugin under lua/custom/plugins
. This file should contain the setup / configuration for the plugin and would be required by the plugin; for example, require 'custom.plugin-name'
. While this configuration could be kept with the plugin spec, breaking it out makes it easier to make changes and :source %
the file, applying the changes without having to restart Neovim.
lua/utils
Groupings of helper functions required elsewhere and broken out for maintainability.