How do I configure backup and swap file behavior?
Answer
:set nobackup noswapfile
Explanation
Disabling backup and swap files prevents Vim from creating extra files alongside your source code. Many developers prefer this for cleaner directories.
How it works
:set nobackupprevents creatingfilename~backup files:set noswapfileprevents creating.filename.swpswap files:set nowritebackupprevents creating temporary backups during write
Example
set nobackup
set nowritebackup
set noswapfile
Tips
- Alternatively, redirect them:
:set backupdir=~/.vim/backup// :set directory=~/.vim/swap//moves swap files to a central location- The
//suffix uses the full path for unique filenames - Swap files help recover from crashes — disabling has trade-offs
- Add
*~and*.swpto your.gitignoreif you keep them enabled