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…


This content originally appeared on DEV Community and was authored by Peter Strøiman

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

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"

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

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"

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

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. ↩


This content originally appeared on DEV Community and was authored by Peter Strøiman


Print Share Comment Cite Upload Translate Updates
APA

Peter Strøiman | Sciencx (2024-07-03T09:18:01+00:00) 2. Creating a Sandbox Environment. Retrieved from https://www.scien.cx/2024/07/03/2-creating-a-sandbox-environment/

MLA
" » 2. Creating a Sandbox Environment." Peter Strøiman | Sciencx - Wednesday July 3, 2024, https://www.scien.cx/2024/07/03/2-creating-a-sandbox-environment/
HARVARD
Peter Strøiman | Sciencx Wednesday July 3, 2024 » 2. Creating a Sandbox Environment., viewed ,<https://www.scien.cx/2024/07/03/2-creating-a-sandbox-environment/>
VANCOUVER
Peter Strøiman | Sciencx - » 2. Creating a Sandbox Environment. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/03/2-creating-a-sandbox-environment/
CHICAGO
" » 2. Creating a Sandbox Environment." Peter Strøiman | Sciencx - Accessed . https://www.scien.cx/2024/07/03/2-creating-a-sandbox-environment/
IEEE
" » 2. Creating a Sandbox Environment." Peter Strøiman | Sciencx [Online]. Available: https://www.scien.cx/2024/07/03/2-creating-a-sandbox-environment/. [Accessed: ]
rf:citation
» 2. Creating a Sandbox Environment | Peter Strøiman | Sciencx | https://www.scien.cx/2024/07/03/2-creating-a-sandbox-environment/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.