DEV Community

Peter Strøiman
Peter Strøiman

Posted on

2. Creating a Sandbox Environment

When I started creating the configuration, I already had a working configuration, that should stay the default configuration until I was happy with the new configuration.

Fortunately, this is quite easy. By default, neovim loads the configuration from $HOME/.config/nvim. But you can customise this through environment variables.

First, I create a directory for the configuration and an empty lua file.

mkdir -p $HOME/.config/nvim-new # 1. Create a new folder
cd $HOME/.config/nvim-new       
touch init.lua                 # 2. Create an empty init.lua file
git init                       # 3. I also want to have this in version control
git add init.lua
git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

Now that an empty configuration is created, I point to the new folder using the environment variable, NVIM_APPNAME, so I can launch neovim with

NVIM_APPNAME=nvim-new nvim
Enter fullscreen mode Exit fullscreen mode

In neovim, you can open your config file, :e $MYVIMRC, and see that it is in fact the new empty init.lua file that was created. This is another reason I added an empty file, because if it doesn't exist, neovim will open init.vim instead.

Opening neovim normally of courses uses the original configuration in $HOME/.config/nvim.

A note on version control

Many have all their "dotfiles"1 under version control, and so do I. But my vim configuration is such a complex beast, that while many have that under their dotfiles repository, I prefer to have a separate repository for my vim configuration itself. This allows me to create branches, or like here, easily experiment with different configurations. Having that in the same dotfiles repository would lead to a lot of complexity in my dotfile configuration management.

btw, I use Rake to make the setup the proper symlinks to my dotfiles repository. Maybe I'll write about that one day.

Make the sandbox easier to use

I can make it easier to launch this by creating an alias.

alias nvim-new="NVIM_APPNAME=nvim-from-scratch nvim"
Enter fullscreen mode Exit fullscreen mode

When I run nvim-new, the new empty configuration file is loaded, if I open it with :e $MYVIMRC, I can confirm this in the filename.

Screenshot of neovim displaying that the loaded file is

I don't want to create this alias in every session, so I add it to my .zshrc file,

echo 'alias nvim-new="NVIM_APPNAME=nvim-from-scratch nvim"' >> ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

And now every new zsh session have nvim-new to open my work-in-progress configuration.

Eventually, my nvim folder was renamed to nvim-old, nvim-new was renamed to nvim, and the alias was removed from my .zshrc file. I keep the old config, so I can quickly reference it if I miss something from my old configuration (I have a keyboard shortcut for that, of course)

Next up:

Now that I have a sandbox configuration, it's time to actually start writing the configuration. In the next part of the series, I will add the very fundamental configuration, that will help me edit the configuration.


  1. Dotfiles is a term used for user configuration files, as the filename start with a ".", making it a hidden file on unix-systems. A more recent approach is to have configuration files in (non-hidden) subfolders of a .config folder. 

Top comments (0)