1

I put in my ~/.vimrc file the next lines of code:

filetype plugin on                                                                                                                                  
set omnifunc=syntaxcomplete#Complete

but nothing happened, when I created a file with .c extension and I pressed <Ctrl-X><Ctrl-O> the vim editor popped up a "pattern not found" message. Here one can see my .vimrc: enter image description here

2 Answers 2

2

You have two problems.

First problem

The command filetype plugin indent on tells Vim to:

  • detect the filetype of every buffer,
  • source the appropriate filetype plugin for the detected filetype,
  • source the appropriate indent script for the detected filetype.

Those things happen automatically, as you load a new buffer. In this specific case (and others) the C ftplugin contains this line:

setlocal ofu=ccomplete#Complete

which effectively overrides your:

set omnifunc=syntaxcomplete#Complete

There are several ways to solve this problem but the most sensible is to make your own filetype plugin:

  1. Create ~/.vim/after/ftplugin/c.vim.

  2. Add setlocal omnifunc=syntaxcomplete#Complete to it.

See :help filetype-plugin.

Second problem

As explained under :help ft-syntax-omni, syntaxcomplete#Complete pulls its suggestions from the current syntax definition. Since syntax highlighting is not enabled by default and you don't enable it explicitly, there is no "current syntax" and thus no syntax-based completion.

You are supposed to enable it explicitly, in your vimrc:

syntax on

Conclusion

This is how your vimrc should look like:

filetype plugin indent on
syntax on

And this is your brand new custom filetype plugin for C:

" ~/.vim/after/ftplugin/c.vim
setlocal omnifunc=syntaxcomplete#Complete
Sign up to request clarification or add additional context in comments.

Comments

0

The syntax code completion uses current language keywords to complete the text. If the text doesn't match any keyword, it says "pattern not found". For example, in a .c file

func| -> function
abc| -> "pattern not found"

See :h ft-syntax-omni for details.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.