Backing up Dotfiles
Here's a walkthrough for backing up your dotfiles on git.
What are dotfiles
"Dotfiles" are those files that sit in some root directory, are hidden by their .
prefix and configure stuff.
A common example is the configuration file for your code editor.
In nvim, this is the file at ~/.config/nvim/init.lua
. If you were on vim, this is the equivalent of your ~/.vim/vimrc
file or your emacs ~/.emacs.d/init.el
.
As an example, here's how you can back up your init.lua
for neovim config on git.
Write your init.lua
This editor config file fits in a wide class of files that I call dotfiles -- those files that sit in some root directory, are hidden by their .
prefix and configure stuff.
I put this init.lua
file in a gitrepo, along with other dotfiles:
mkdir -p ~/dev/dotfiles/nvim
nvim ~/dev/dotfiles/init.lua
Back up your dotfiles
Now instead of just leaving this file on your local machine, you can clone it somewhere on git:
cd ~/dev/dotfiles
git init
git remote add origin git@github.com:jaketrent/dotfiles.git
git add .
git commit -m "initial commit"
git push origin HEAD
Link to git-controlled init.lua
Now instead of using the generated nvim init.lua
defaults, if they've been made, we're going to delete them:
cd ~/.config/
rm -rf nvim
Once they're deleted, now we can create a soft symlink to the dotfiles
repo directory for nvim:
ln -s ~/dev/dotfiles/nvim
Test the link
Let's verify that the link points to the right place:
❯ ls -la
...
lrwxr-xr-x 1 jaketrent staff 34 Jul 5 08:45 nvim -> /Users/jaketrent/dev/dotfiles/nvim
...
Then start nvim and immediately run the scriptnames
command:
nvim +scriptnames
The output should include the init.lua
, in your dotfiles
directory, meaning that vim is running with that script loaded:
after/plugin
...
3: ~/dev/dotfiles/nvim/init.lua
...
Now get configuring, and make nvim yours!
Reversing the process
Let's say that have the init.lua
file in git somewhere, and now you have a new local computer. You need to clone that repo and then link it in the ~/.config
folder in the same way:
mkdir ~/dev
cd ~/dev
git clone git@github.com:jaketrent/dotfiles.git
cd ~/.config
ln -s ~/dev/dotfiles/nvim
Full circle. Never lose your nvim config again.