vimtricks.wiki Concise Vim tricks, one at a time.

How do I configure Vim's built-in auto-completion?

Answer

:set completeopt=menu,menuone,noselect

Explanation

The completeopt option controls the behavior of the completion popup menu. Proper configuration makes <C-n> and <C-p> completion more user-friendly.

How it works

  • menu shows a popup menu with matches
  • menuone shows the menu even with a single match
  • noselect does not auto-select the first item
  • noinsert does not auto-insert text

Example

set completeopt=menu,menuone,noselect

Now <C-n> in insert mode shows a popup without auto-inserting.

Tips

  • <C-n> triggers keyword completion
  • <C-x><C-f> completes file paths
  • <C-x><C-l> completes whole lines
  • <C-x><C-o> triggers omni completion
  • <C-y> accepts the selected completion
  • <C-e> cancels the completion menu

Next

How do you yank a single word into a named register?