Hiding swp, ~ files in the default Vim file browser

1.5k Views Asked by At

I'm using the default file browser in Vim a lot. But the annoyance is that it's showing swap files, .orig, .php~ etc. Can I hide these files somehow?

On a related note, why doesn't Vim always return to the file browser when pushing Ctrl-6?

4

There are 4 best solutions below

0
On BEST ANSWER

Unless you want to move the swap and backup files to another (single) directory (as outlined in the answer of the Tin Man), you have to configure the built-in netrw plugin (which provides the file browser), as described in :help g:netrw_list_hide:

:let g:netrw_list_hide= '.*\.swp$,\~$,\.orig$'

Put this into your ~/.vimrc to make it permanent.

0
On

Most probably this files appears because Vim was closed before the buffer was written to its original file/location. Always enter :write or :update before quitting Vim.

0
On

Vim lets you define where your backup and swap files reside. It's pretty common to tell Vim to use either a local tmp directory (~/tmp), or a somewhere else semi-out-of-the-way.

You can define the location using the following commands in your $MYVIMRC file (typically ~/.vimrc). I use:

set backup                    " keep a backup file
set backupdir=~/.vim/_backups " store backups here
set directory=~/.vim/_swaps   " store swap files here

I've created _backups and _swaps in my ~/.vim directory.

Use h directory and h backupdir in Vim to read the documentation about the two settings.

0
On

Instead of using Ctrl-^, try :Rex.

With netrw v151, :Rex can also return from the netrw browser to the last file being edited in that window, too.