Putting the `~/.config/nvim` folder in a `git` repo

I have a Github repo where I keep all of my terminal conigurations, so I can clone that to a couple different machines and have the same experience.
I have a few questions:

  1. Is there a way to add my ~/.config/nvim to that repo?
  2. Is it even a good idea to add the entire folder?
  3. If I did, would I also need to add the ~/.local/share/nvim folder too? Or can I reconstruct it on each system?
  1. Yes, there are a lot of ways. I don’t want to overwhelm you, so I will suggest you two of them: “Only git” and “Git + GNU Stow
  • “Only git” - These resources all you need to get the idea: article

Pros: you need only git, nothing more
Cons: you can accidentally delete all files not tracked by git with git clean, you can see a lot of files in git status (there is a way around - for example, disable
status.showUntrackedFiles option)

  • Git + GNU Stow” - the idea is that you create symlinks to files in your repo (repo where you have moved all your configs to). How does it look like:
    I have git repo with all configs i care in $HOME/github/dotfiles/:
i3
└── .config
   └── i3
      ├── config
      └── script
nvim
└── .config
   └── nvim
      ├── init.lua
      ├── lazy-lock.json
      └── lua
scripts
└── .local
   └── bin
      ├── tmux-sessionizer
      └── tmux-windowizer
tmux
└── .config
   └── tmux
      ├── plugins
      └── tmux.conf
...

Pay attention to directory layout, I mirrored $HOME directory (need for stow to correctly place symlinks). After that, I run in root of this repo:

stow --target=$HOME nvim tmux scripts ...

Stow has created symlinks to the repo. There are now links, where the configurations used to be and the configurations themselves are in one place within the repository.

.config/nvim -> ../github/dotfiles/nvim/.config/nvim
.config/tmux -> ../github/dotfiles/tmux/.config/tmux
.local/bin/tmux-sessionizer -> ../../github/dotfiles/scripts/.local/bin/tmux-sessionizer
.local/bin/tmux-windowizer -> ../../github/dotfiles/scripts/.local/bin/tmux-windowizer

These resources will help: article

  1. It seems like it’s the only option, if you want your configuration to work on another machine.
  2. You don’t need them, because there are files of plugins installed by plugin manager and plugins’ logs.

Please let me know if you have any questions or concerns.

More about “Only git”: first, second

More about “Git + GNU Stow”: first, second

Thank you, one thing I would like to know is, is there a way to have “local overrides” for specific systems? The way I have it now is that my .bashrc (local) calls .my_settings (in the repo), so I can do any commands before and after the settings. Is there a way to do that for the NVim configuration?

I am not sure what do you mean.

is there a way to have “local overrides” for specific systems?

What do you mean under “specific systems”? Do you mean Windows/macOS/Linux system-specific code?

so I can do any commands before and after the settings.

Can you give an example of such a command? And I don’t get the part with “before” and “after”,

By “systems” I just meant “computers”, would I be able to change the configuration on different computers?

By “before and after”, I mean this:

# .bashrc


# I can do anything over here (like set environment variables), before the settings in the git repo

# On different computers, I might put the repo other places, on this computer I will put it in ~/.term_settings
export TERM_SETTINGS_DIR=${HOME}/.term_settings

# Now I run the settings in the git repo
source ${TERM_SETTINGS_DIR}/my_settings.sh

# Now I can run any other commands after it, like changing an alias
alias ls='ls --color=never' # this computer doesn't support colors, so I will overwrite the alias I have set in `my_settings`

I understand it now.

Is there a way to do that for the NVim configuration?

After I got the idea of your approach, I need to know what language do you primarily use for nvim configuration? Lua or vimscript? But anyway you can run lua code from vimscript and vimscript feom lua.

For example, if you use lua (i dont know vimscript well), I would suggest the following:
You have file on computer locally, something like “local_overrides.lua”, and you require it in your config files in your repo.

Something like this, so if some computer have this file, it will run code, if computer haven’t, it will do nothing.

local ok, _ = pcall(require, "local_overrides")
if ok then
  -- your code
end

And your local_overrides.lua look something like this:

local M = {}
-- local variables
local x = 1

--local functions 
local function bar(...) ... end

-- functions you can use in your configs where you have required this file
function M.foo(...)
...
end

function M.baz(...)
...
end

return M

So the answer to your question is yes. I think you need to open new topic for specifics.