Part of setting in my .vimrc.

cat .vimrc
autocmd FileType txt setlocal omnifunc=CompleteMonths 
fun! CompleteMonths(findstart, base)
  if a:findstart
    " locate the start of the word
    let line = getline('.')
    let start = col('.') - 1
    while start > 0 && line[start - 1] =~ '\a'
      let start -= 1
    return start
    " find months matching with "a:base"
    let res = []
    for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")
      if m =~ '^' . a:base
    call add(res, m)
    return res

Now edit a test.txt file in vim. Input J and press <c-x><c-o> ,why no month complete menu pop up?

1 Answer 1


You need to change your autocmd to

autocmd FileType text set omnifunc=CompleteMonths

The file type for .txt files is text not txt and omnifunc is already local to the buffer (see :h 'omnifunc')

You also need to make sure that you have a line like this in your vimrc to be sure that the filetype is set:

filetype plugin on

With these modifications on your vimrc, the completion works on my setup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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