Hide Vim backups (* ~) in Windows Explorer

On Windows, I usually work with Total Commander, which can be easily configured to completely ignore these *.*~ And *~ . But sometimes, when I switch to Windows Explorer, I get a little confused with all these "unknown" files.

Can I configure Vim so that for each backup it creates, it also sets the “hidden” attribute?

Or set up a good workaround?

I know that I can configure Vim to put them in another directory, but I would like to avoid this, because IIUC may suffer from name conflicts.

+5
source share
3 answers

If the backup parameter is set, vim updates the backup file every time we write the file with :w . And every time he creates a file that is not hidden, even if you forcibly hidden it earlier! Therefore, we need to do something every time we write a buffer to a file.

You can do it on windows. In the _vimrc file (usually in 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 ensures that the backup file will be hidden with each write to the file from the buffer. Why every time? Cos vim creates a non-hidden file with every recording!

But you have to live with a blinking black window (the command window where we execute the attrib ) every time you save the file, but you are in pain :)

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

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

Hope this helps everyone who is trying to find how to hide vim backup files.

+5
source

Some time ago I wrote a plugin for this called autohide . It works by setting the “hidden” attribute after recording, as suggested in Pavan’s answer. By default, this is done only for swap files, viminfo, and persistent undo files; You can only hide backup files by setting let g:autohide_types='b' in your .vimrc, or add it to the default list instead of 'suvb' instead of just 'b' .

The benefits of the manual method in Pavan's answer include handling additional file types, arbitrary file templates (such as dotted files) and some error handling (especially those associated with slow network shares that do not allow you to set attributes immediately after creating the file).

+3
source

I have this in my _gvimrc :

 set nobackup 

First of all, backup files are not created. However, the swap file ( .*.swp ) is still created during editing (and deleted when Vim closes). Therefore, if your computer fails, you can still restore your changes.

+1
source

Source: https://habr.com/ru/post/1403610/


All Articles