2

My email client creates files in /tmp and my password manager under /dev/shm when editing. The first is just unnecessary to store the undos for longer than the lifetime of the file, the latter is leaking passwords to my undodir.

How can I disable both undodir and backupdir for these two specific paths?

1 Answer 1

2

For undo you can check :h undo-persistence topic:

5. Undo persistence     *undo-persistence* *persistent-undo*

When unloading a buffer Vim normally destroys the tree of undos created for
that buffer.  By setting the 'undofile' option, Vim will automatically save
your undo history when you write a file and restore undo history when you edit
the file again.

The 'undofile' option is checked after writing a file, before the BufWritePost
autocommands.  If you want to control what files to write undo information
for, you can use a BufWritePre autocommand: >
    au BufWritePre /tmp/* setlocal noundofile

I am not so sure about backup, as the option is global and you can't easily set it per buffer, but there is backupskip option you can try to use:

                        *'backupskip'* *'bsk'*
'backupskip' 'bsk'  string  (default: "$TMPDIR/*,$TMP/*,$TEMP/*"
                 Unix: "/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*"
                 Mac: "/private/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*")
            global
    A list of file patterns.  When one of the patterns matches with the
    name of the file which is written, no backup file is created.  Both
    the specified file name and the full path name of the file are used.
    The pattern is used like with |:autocmd|, see |autocmd-patterns|.
    Watch out for special characters, see |option-backslash|.
    When $TMPDIR, $TMP or $TEMP is not defined, it is not used for the
    default value.  "/tmp/*" is only used for Unix.

Something like:

set backupskip+=/dev/shm/*

Your Answer

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

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