I have a really large file with many paths in it. I don't want it to participate in any of the completion mechanisms. Is there a way to mark a particular buffer as "not a candidate for keyword completion" or, equivalently, to close it as soon as I leave the buffer?

Here's some motivation for doing it.

I have a file called ~/FILES that consists of two columns like this, with the name of a file in the left column and the full path on the right. It's just a manually generated index with a very simple format.

Here's an excerpt of the file showing part of the Linux kernel source.

ABCDBCDA.c                              ~/ws/opt/linux/tools/lib/lockdep/tests/ABCDBCDA.c
ABCDBDDA.c                              ~/ws/opt/linux/tools/lib/lockdep/tests/ABCDBDDA.c
ABI.txt                                 ~/ws/opt/linux/Documentation/devicetree/bindings/ABI.txt
ABI.txt                                 ~/ws/opt/linux/Documentation/mn10300/ABI.txt

This file is very long and really slows down keyword completion.

I've been using this binding to delete the buffer when following paths using gf, the most common way to exit the ~/FILES buffer.

nnoremap <silent> gf gf:silent! bdelete ~/FILES<cr>

but it's really modifying the behavior in the wrong place.

Is there a better way of marking the buffer?

  • you could set the 'bufhidden' option for that buffer. Not sure it will achieve what you actually want. Apr 11, 2018 at 6:18
  • When you say "not a candidate for keyword completion", do you mean that you don't want the words in that file to be included as possible completions when you are editing other files?
    – Rich
    Apr 11, 2018 at 9:49
  • @Rich yes exactly. Semantically the ~/FILES file is not a file I’m editing, it’s a naive way of emulating an almost-plugin. @ChristianBrabandt I will try that and report back. Apr 11, 2018 at 16:53

1 Answer 1


If I understand what you're asking for, you could use autocmd to close ~/FILES when you leave this buffer.

autocmd BufLeave,BufWinLeave ~/FILES :bd ~/FILES

This way, everytime you "leave" this buffer (using :e or :n etc.) it will close ~/FILES.

Hope this helps.

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.