How do I autocomplete Vim command names and their arguments while in insert mode?
Answer
<C-x><C-v>
Explanation
The <C-x><C-v> key sequence in insert mode triggers Vim command-line completion — the same completion engine used at the : command prompt. This lets you type a partial Vim command and get a completion menu right inside your buffer, which is invaluable when editing .vim files, init.vim, or any Vimscript source.
How it works
<C-x>enters the sub-completion menu (part of Vim's completion sub-mode)<C-v>selects the command-line completion provider- Vim looks at the word before the cursor and suggests matching Ex commands, options, function names, and their arguments
The completion menu behaves identically to the : command line, including support for options after set, event names after autocmd, and arguments for any built-in command.
Example
While editing your init.vim, you type:
set comple
Pressing <C-x><C-v> opens a completion menu offering:
set complete
set completefunc
set completeopt
set completeslash
Select with <C-n> / <C-p> and press <Enter> or any key to confirm.
Tips
- Useful in any file, not only Vimscript — for example, completing shell command names if
shell-related options are typed - After completing a command, pressing
<C-x><C-v>again will advance to argument completion, mirroring what happens on the actual command line - Works alongside
omnifuncand other completions; press<C-n>inside the popup to navigate