1

I have set

vim.opt.backup = true

which keeps permanent backups. (Works as intended thus far.)

But I would like to exclude certain filetypes, or, even better, file extensions. (Say, .conf which I would prefer to set to keep the original with patchmode.)

Is there a way to do that? ( Exclude some extensions from backup and set only some extensions for patchmode.)

I am using neovim.

Example:

I have two files: an example1.conf and an example2.text

Setting backup will create an example.conf.bak and an example.text.bak (or example1.conf~ and example2.text~ as per the original behavior.)

Setting patchmode will create example1.conf.orig and example2.text.orig respectively.

Given my aim is to have example1.conf.orig amd example2.text.bak,

I read the :h on backupskip.

But (if I understand :h correctly,) backupskip applies both to backup and patchmode.

Therefore, if I was to add the extension .conf to backupskip, I would end up with no example1 backup or original, and example2.text.bak along an exampl2.orig

1 Answer 1

2

Unfortunately backup is a global option. The only way to keep it on but disable backups for certain files is to use backupskip, which is a list of file-patterns (see :help 'backupskip'). It could be difficult to accurately cover filetypes with such an option.

Be careful to add to the defaults rather than overwrite them, unless you don't like that it skips backups on files that are likely to be temporary.

11
  • Thank you. Backupskip indeed looks less than ideal. I hope it takes a *.conf value withour complaining, though it clearly doesn't seem designed to do that. Pretty big omission for an editor like vim / neovim. Any idea on how to (at the same time,) set patchmode for only some file types? Would autocmds have any effect?
    – Anthony
    Aug 13, 2023 at 22:32
  • The only other solution I can see is toggling it off, writing, and back on @Anthony. Looks like patchmode is also global. The pattern for backupskip should be able to use *.conf, since it's an :help autocmd-patterns
    – D. Ben Knoble
    Aug 14, 2023 at 20:34
  • Could you explain it in more detail?
    – Anthony
    Aug 16, 2023 at 4:41
  • This comment is only meant to tag you, since I forgot to do so in my previous one. @D.BenKnoble
    – Anthony
    Aug 16, 2023 at 5:02
  • @Anthony explain which in more detail? Toggling + writing, patchmode, or backupskip + *.conf?
    – D. Ben Knoble
    Aug 16, 2023 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.