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

How do I customize the behavior of Vim's insert-mode completion popup menu?

Answer

:set completeopt=menu,menuone,noselect

Explanation

The completeopt option controls how Vim's built-in completion popup menu behaves — whether it appears automatically, whether an item is pre-selected, and whether a preview window opens. Tuning this option makes completion feel responsive and predictable.

Values

Value Effect
menu Show a popup menu when there are multiple matches
menuone Show popup even if there is only one match
noinsert Do not insert any text until you explicitly select a match
noselect Do not auto-select the first match — menu starts with nothing highlighted
preview Show extra info in a preview window
popup Show extra info in a floating popup (Vim 8.1.1882+)
longest Only insert the longest common substring of all matches

Common configurations

IDE-like (show menu, don't pre-select):

set completeopt=menu,menuone,noselect

Auto-complete friendly (don't insert until selected):

set completeopt=menu,menuone,noinsert

Minimal (longest common match, then refine):

set completeopt=longest,menu

How completion works

  • <C-n> / <C-p> — trigger keyword completion (next/previous)
  • <C-x><C-o> — omni completion (language-aware)
  • <C-x><C-f> — filename completion
  • <C-x><C-l> — whole line completion

Tips

  • noselect is essential if you want <CR> to insert a newline when nothing is selected, rather than confirming the first match
  • Most completion plugins (coc.nvim, vim-mucomplete) document their recommended completeopt value — check their README
  • popup (Vim 8.2+) shows documentation in a floating window next to the menu — cleaner than the preview window
  • :set completeopt? shows the current value

Next

How do I run a search and replace only within a visually selected region?