Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use vim's :browse oldfiles a lot to edit files I've recently worked with. However, there are some files, such as git's auto-generated COMMIT_EDITMSG, which clutter that list and which I never need to edit explicitly. Is there a way to filter filenames out from being displayed (or, better) saved in that list, perhaps using a regex or similar?

share|improve this question
up vote 1 down vote accepted

You can use the (quick) function below to filter out commit messages from the v:oldfiles variable before the actual browsing:

function! CleanBrowse()
    call filter(v:oldfiles, 'v:val !~ "COMMIT_EDITMSG"')
    browse :oldfiles
nnoremap <F6> :call CleanBrowse()<CR>

It doesn't change the content of your ~/.viminfo so it seems to be relatively safe.

More information:

:h :oldfiles
:h v:oldfiles
:h list-functions
:h filter()
:h !~

I don't know of a way to decide what should and what shouldn't be saved in ~/.viminfo but I would be curious to learn.

share|improve this answer
That works. Unfortunately it doesn't affect the filelist saved, which means (in my case for example) only 19 entries are shown rather than 20, once COMMIT_EDITMSG is filtered out. But it does clean up the list, thanks. – Andrew Ferrier May 18 '13 at 16:11
You could easily remove the COMMIT_EDITMSG lines from your ~/.viminfo with something like :g/COMMIT_EDITMSG/d but v:oldfiles is defined at startup so you would need to restart Vim each time you do that cleanup. – romainl May 18 '13 at 18:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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