vimtricks.wiki Concise Vim tricks, one at a time.

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 nobackup prevents creating filename~ backup files
  • :set noswapfile prevents creating .filename.swp swap files
  • :set nowritebackup prevents 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 *.swp to your .gitignore if you keep them enabled

Next

How do you yank a single word into a named register?