Take the 2-minute tour ×

I frequently accidentally open a binary executable, i.e. "foo", when I mean to open the associated source code "foo.cpp". The root of the problem is that tab completion, i.e. :e fo<tab> typically lands on the binary instead of the source code.

Is there a way to get vim to only tab complete names of text files? Or alternatively, change the tab completion order?

Sometimes my hasty tab completion error happens outside of vim; for those cases, what is the best way to prevent vim from opening files that are not text?

share|improve this question
How would vim know if a file is binary or not? It'd have to open and inspect them, which is pretty heavy for tab completion. Even if a file is executable, it can still be plain text. –  Matt Greer Apr 26 '11 at 16:16

3 Answers 3

up vote 10 down vote accepted

Not exactly what you need, but I have something like this in my .vimrc

" ignore these files when completing names and in Ex
set wildignore=.svn,CVS,.git,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,*.pdf,*.bak,*.beam
" set of file name suffixes that will be given a lower priority when it comes to matching wildcards
set suffixes+=.old
share|improve this answer
From help for suffixes option: "An empty entry, two consecutive commas, match a file name that does not contain a ".", thus has no suffix. This is useful to ignore "prog" and prefer "prog.c"." –  taro Apr 26 '11 at 17:14

For tab completion outside of vim, that will depend on your shell. Most shells have some form of autocompletion support. In particular, Zsh has the ability to autocomplete e.g. remote hosts for ssh. I'm not a wizard with these things, but it would probably be relatively simple to get your shell to drop files with certain suffixes from the autocompletion list when the command you are typing starts with "vim".

A quick google search turn up this page, which has this:

# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
'*?.old' '*?.pro'

It should not be too difficult to modify this logic to get what you want (if you use Zsh).

share|improve this answer

Maybe you can find this useful:

set wildmenu
set wildmode=longest,list

(taken and using from How do I make vim do normal (bash like) tab completion for file names?)

share|improve this answer

Your Answer


