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

How do I complete identifiers using ctags from within insert mode?

Answer

<C-x><C-]>

Explanation

Pressing <C-x><C-]> in insert mode opens a completion menu populated from your project's tags file. This lets you auto-complete function names, class names, variable names, and other identifiers that ctags has indexed — without leaving insert mode or relying on a language server.

How it works

  • <C-x> enters Vim's sub-completion mode, which unlocks a range of specialized completion sources
  • <C-]> (after <C-x>) selects tag-file completion specifically
  • Vim searches the tags file (or all files listed in 'tags' option) for entries matching what you've typed so far
  • Navigate the menu with <C-n> (next) and <C-p> (previous), confirm with <C-y> or <Esc>

Example

With a C project and a tags file generated by ctags -R .:

Insert: parse_<C-x><C-]>

Vim shows a completion menu:

parse_expression
parse_statement  ← selected
parse_token

Select the entry and press <C-y> to confirm.

Tips

  • Generate a tags file with ctags -R . from your project root (requires Universal Ctags or Exuberant Ctags)
  • Set 'tags' to search upward: set tags=./tags,tags;/ — the trailing ;/ causes Vim to walk up directories until it finds a tags file
  • <C-x><C-p> completes from the current buffer and 'include' files; <C-x><C-]> uses only the tags file
  • Works alongside LSP setups — fall back to this when no LSP is available

Next

How do I open files in subdirectories without a fuzzy finder plugin?