Question

On Windows, I normally work with Total Commander, which can easily be configured to ignore these *.*~ and *~ completely. But occasionally when I switch to Windows Explorer, I get little bit confused with all that "unknown" files/.

Can I set up Vim so that for every backup it creates it will also set "hidden" attribute?

Or set up some nice workaround?

I know I can set up Vim to put these in other directory, but I'd like to avoid that, since IIUC, it could suffer from naming conflicts.

Was it helpful?

Solution

If the backup option is set, vim updates the backup file every time we write the file with :w. And every time, it creates a file which is not hidden even though you had forcibly hidden it previously! So we need to do something everytime we write the buffer into file.

You can do this on windows. In your _vimrc file ( generally found at C:\Program Files (x86)\Vim ), add this line

autocmd BufWritePost,FileWritePost * silent ! attrib +h <afile>~

Where,

attrib=Windows File attribute changinf command
<afile>= Name of the file being sourced
silent= Prevent an annoying command window from popping up and asking user to press a key

This will make sure that the backup file gets hidden with every write to file from buffer. Why every time? Cos vim creates a non-hidden file at every write!

But you have to live with a flashing black window ( command window where we are running attrib command ) every time you save your file, but worth the pain :)

On linux/unix systems you can add this in your .vimrc

autocmd BufWritePost,FileWritePost * silent ! mv <afile>~ .<afile>

Hope this helps all those trying to find how to hide vim backup files.

OTHER TIPS

I wrote a plugin for this a while back called autohide. It works by setting the "hidden" attribute after write as suggested in Pavan's answer. By default it only does this for swap files, viminfo, and persistent undo files; you can make it only hide backup files by configuring let g:autohide_types='b' in your .vimrc, or add it to the default list instead with 'suvb' instead of just 'b'.

Benefits over the manual method in Pavan's answer include handling of additional file types, arbitrary file patterns (like dotfiles), and some error handling (especially related to slow network shares that don't allow setting attributes right away after creating a file).

I have this in my _gvimrc:

set nobackup

No backup files are generated in the first place. However, the swap file (.*.swp) is still generated during editing (and deleted when you close Vim). So if your computer crashes, you can still recover your changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top