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

For example, for any file that ends in .foo, I would like the following behavior in vim:

  • if the user types i., I want vim's autocomplete to provide the list dogs, cats, mice
  • if the user types i.dogs., I want vim's autocomplete to provide the list poodle,dachshund,pitbull

fwiw, I need to use this functionality in a customized language for easy typing/learning.

share|improve this question
up vote 2 down vote accepted

You can write a custom insert-mode completion via 'omnifunc' or 'completefunc'. Read up on the details at :help complete-functions; there are also examples.

Vim uses filetypes (e.g. java, c, markdown) as a abstraction over file extensions, which are only one way to represent the type of file (others are e.g. the #!/bin/bash hashbang lines at the top of an executable script). You can write a custom filetype detection, like this:

:autocmd BufNewFile,BufRead *.foo setf foo

And then put your custom completion in ~/.vim/ftplugin/foo_completion.vim with contents like this:

:setlocal completefunc=FooCompletion

I hope these pointers help; please refer to the help and existing filetypes for the details.

share|improve this answer

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.