Ignore Vim Files Everywhere With a Global gitignore
Posted 2021-01-12
tl;dr: Put a
gitignore
somewhere on your computer, such as~/.gitignore
. Then to tell git to use it, use the commandgit config --global core.excludesfile ~/.gitignore
. Now anything included in~/.gitignore
will be ignored in your commits on all projects.
If you’re a vim user like me, you’re probably used to including some vim settings in your gitignore. This is normally what I’ve done in all my side-projects. When I put a PR in on a new project, I again included the vim settings. The PR got kicked back with a suggestion to instead put the vim settings in my global gitignore.
My what?
Turns out that’s a thing. Instead of having to include the vim settings in every gitignore on every project, I can just include it once on my computer and it applies to every project.
If everyone on your team used vim (or VSCode, or the JetBrains family of IDEs) it might make sense to include that stuff in your project’s gitignore
. However, it’s a better practice to only include the things directly related to your project. node_modules
is generated by the project, so keep it in your project’s gitignore.
An .idea/
folder isn’t.
To enable a global gitignore, put a gitignore
file in some central location. I put mine in ~/.gitignore
. Inside I included the default stuff I ignore for vim generated by gitignore.io.
### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
Session.vim
Sessionx.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
Finally, use this command to tell git where your global gitignore
is:
git config --global core.excludesfile ~/.gitignore