git ignore vim temporary files
Solution 1:
Vim temporary files end with ~ so you can add to the file .gitignore
the line
*~
Vim also creates swap files that have the swp and swo extensions. to remove those use the lines:
*.swp
*.swo
This will ignore all the vim temporary files in a single project
If you want to do it globally, you can create a .gitignore file in your home (you can give it other name or location), and use the following command:
git config --global core.excludesfile ~/.gitignore
Then you just need to add the files you want to ignore to that file
Solution 2:
Alternatively you can configure vim to save the swapfiles to a separate location,
e.g. by adding lines similar to the following to your .vimrc
file:
set backupdir=$TEMP//
set directory=$TEMP//
See this vim tip for more info.
Solution 3:
This is something that should only be done on a per-user basis, not per-repository. If Joe uses emacs, he will want to have emacs backup files ignored, but Betty (who uses vi) will want vi backup files ignored (in many cases, they are similar, but there are about 24,893 common editors in existence and it is pretty ridiculous to try to ignore all of the various backup extensions.)
In other words, do not put anything in .gitignore
or in core.excludes
in $GIT_DIR/config
. Put the info in $HOME/.gitconfig
instead (as nunopolonia suggests with --global
.) Note that "global" means per-user, not per-system.
If you want configuration across the system for all users (which you don't), you'll need a different mechanism. (Possibly with templates setup prior to initialization of the repository.)
Solution 4:
I would also recommend to think to ignore files like:
.*.swp
.*.swo
as you may have files that end with .swp