github/gitignore · Global/Vim.gitignore
Vim .gitignore Template Explained
A step-by-step look at Vim.gitignore's swap file bracket pattern ([._]*.s[a-v][a-z]), the !*.svg exception, and the session, undo and tags rules.
Vim.gitignore is the template that uses bracket range patterns most aggressively. Vim creates a .filename.swp swap file for each file being edited, and if a swap file already exists it uses a new name by changing the last letter, as in .swo and .swn.
Instead of listing every possible extension, it catches them all at once with ranges such as [a-v][a-z], but that range also includes .svg, so there is a line that restores them with !*.svg.
Rules explained
| Pattern | What it ignores and why |
|---|---|
[._]*.s[a-v][a-z][._]*.sw[a-p][._]s[a-rt-v][a-z][._]ss[a-gi-z][._]sw[a-p] | Swap filesThe first line catches files that start with a dot (.) or underscore (_) and end in .saa through .svz. [._]*.sw[a-p] catches .swa through .swp, and the last three lines catch swap files with no file name before the extension, such as .swp. |
!*.svg | SVG exception[._]*.s[a-v][a-z] also ignores SVG files that start with a dot or underscore, such as .icon.svg or _logo.svg, so every .svg is re-included. It is an example of why rule order matters. |
Session.vimSessionx.vim | SessionsWindow layouts and lists of open buffers saved by :mksession. They are personal work state and are not shared. |
[._]*.un~*~ | Undo and backupsPersistent undo files created when the undofile option is on, and backup files from the backup option. |
.netrwhisttags | netrw and tagsVisit history of the built-in file explorer netrw and tag files created by ctags. tags ignores both files and folders named exactly tags. |
Practical notes
- Because of the
tagsrule, source folders such assrc/tags/can be ignored. If you have such a folder, add!src/tags/or narrow the rule to/tags. - If you collect swap files in one place in your Vim config, as in
set directory=~/.vim/swap//, they are never created in project folders at all. - Neovim uses swap files of the same format, but its default location is the state directory, so they rarely appear in projects.
Original template
Vim.gitignore
# Swap[._]*.s[a-v][a-z]# comment out the next line if you don't need vector files!*.svg[._]*.sw[a-p][._]s[a-rt-v][a-z][._]ss[a-gi-z][._]sw[a-p]# SessionSession.vimSessionx.vim# Temporary.netrwhist*~# Auto-generated tag filestags# Persistent undo[._]*.un~
Templates from github/gitignore/Global/Vim.gitignore @356fd7b (2026-09-11) · CC0-1.0