3

I've got this password file, and when editing this in vim I want to make sure vim does not create a swap/backup file. How to set this?

I have seen this: How to prevent vim from creating (and leaving) temporary files?

But I do not want this for all files, just for a specific one. Is this possible?

Community
  • 1
  • 1
User402841
  • 106
  • 3
  • 16
  • 40

2 Answers2

4

If your file can contain comments you can set the nobackup and noswapfile by adding a modeline to the start or end of the file.

Something like this:

# vim: set nobackup noswapfile:
Michael Anderson
  • 66,195
  • 7
  • 128
  • 177
3

You could use autocmd to set nobackup for that filename or filenames matching a specific pattern/extension:

autocmd BufRead,BufNewFile passwordfilename set nobackup
autocmd BufRead,BufNewFile passwordfilename set noswapfile
Michael Berkowski
  • 260,803
  • 45
  • 432
  • 377