# Vim Autocomplete Not Working

You press <C-n> or <C-x><C-o> expecting completions but nothing happens or you get irrelevant suggestions. Vim's completion system is powerful but can be finicky. Here's how to fix it.

Built-in Completion Basics

Vim has multiple completion modes, triggered by different key sequences:

ShortcutCompletion Type
<C-n>Next match from all buffers
<C-p>Previous match from all buffers
<C-x><C-n>Keywords from current buffer
<C-x><C-i>Keywords from included files
<C-x><C-]>Tags
<C-x><C-f>File names
<C-x><C-o>Omni completion (language-aware)

If <C-n> works but <C-x><C-o> doesn't, the issue is with omnicompletion setup.

Omnicompletion Not Working

Omnicompletion requires a filetype-specific completion function. Check if one is set:

vim
:echo &omnifunc

If empty, you need to enable filetype plugins:

vim
filetype plugin on

Now check again for a specific file type:

bash
vim myfile.py
vim
:echo &omnifunc

For Python, you should see something like pythoncomplete#Complete. If still empty, the omnifunc isn't being set.

Set Omnifunc Manually

If filetype detection isn't setting omnifunc, set it manually:

vim
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS

JavaScript/TypeScript Completion

Built-in JavaScript completion is limited. For better results, use a dedicated plugin.

With coc.nvim:

```vim " Install with vim-plug Plug 'neoclide/coc.nvim', {'branch': 'release'}

" Use Tab for completion inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" ```

Python Completion Issues

Python completion requires a properly configured environment. Check if jedi is available:

vim
:echo has('python3')

If 0, you need Vim with Python support:

```bash # Ubuntu/Debian sudo apt install vim-nox

# macOS brew install vim ```

For better Python completion, use coc.nvim or deoplete with jedi:

vim
Plug 'deoplete-plugins/deoplete-jedi'

The popup menu should appear automatically. If it doesn't:

  1. 1.Check completeopt:
vim
:set completeopt?

Recommended setting:

vim
set completeopt=menuone,longest,preview
  • menuone: Show menu even for single match
  • longest: Insert longest common text
  • preview: Show extra information
  1. 1.Check if popup is being suppressed:
vim
:set pumheight?

A very low value hides the menu. Set higher:

vim
set pumheight=15

No Completion Suggestions

If the menu appears but is empty:

  1. 1.Words exist in current buffer? Type some words first, then try completion.
  2. 2.Check complete option:
vim
:set complete?

Default includes current buffer, other buffers, and more:

vim
set complete=.,w,b,u,t,i
  1. 1.For file completion (<C-x><C-f>), ensure you're in a path context:
vim
" Start typing a path
:edit ./src/
" Press <C-x><C-f> to complete filenames

YouCompleteMe Issues

YCM requires compilation. Common issues:

vim
" Check if YCM is loaded
:YcmDiags

If you get "Unknown function", YCM isn't loaded.

Reinstall/compile YCM:

bash
cd ~/.vim/plugged/YouCompleteMe
python3 install.py --all

For specific languages:

bash
python3 install.py --ts-completer  # TypeScript
python3 install.py --go-completer  # Go
python3 install.py --rust-completer  # Rust

coc.nvim Issues

Check coc status:

vim
:CocInfo

Common issues:

  1. 1.Node.js not installed or wrong version:
bash
node --version  # Need 16.x or higher
  1. 1.Extensions not installed:
vim
:CocInstall coc-pyright
:CocInstall coc-tsserver
:CocInstall coc-html
  1. 1.Language server not found:
vim
:CocCommand languageserver.check

deoplete Issues

Check deoplete status:

vim
:echo deoplete#is_enabled()

If 0, deoplete isn't initialized. Ensure you have:

vim
let g:deoplete#enable_at_startup = 1

Completion Too Slow

If completion lags:

  1. 1.Reduce sources:
vim
" For deoplete
call deoplete#custom#option('sources', {
    \ '_': ['buffer', 'file'],
    \ 'python': ['jedi'],
    \ })
  1. 1.Add delay:
vim
let g:deoplete#auto_complete_delay = 100
  1. 1.For coc, reduce trigger length:
vim
" In coc-settings.json
{
    "suggest.minTriggerInputLength": 2
}

Completion Disappearing Too Quickly

If the completion menu closes before you can use it:

vim
set completeopt-=noselect

And ensure you're using Tab/arrow keys, not mouse (which might close it).

Snippet Integration

For snippet expansion with completion, install a snippet engine:

```vim Plug 'SirVer/ultisnips'

" Tab to expand let g:UltiSnipsExpandTrigger = "<Tab>" let g:UltiSnipsJumpForwardTrigger = "<Tab>" let g:UltiSnipsJumpBackwardTrigger = "<S-Tab>" ```

LSP-Based Completion (Neovim)

For Neovim 0.5+, use native LSP:

```lua local lspconfig = require('lspconfig')

-- Setup a language server lspconfig.pyright.setup{}

-- Configure completion local cmp = require('cmp') cmp.setup({ mapping = { ['<Tab>'] = cmp.mapping.select_next_item(), ['<S-Tab>'] = cmp.mapping.select_prev_item(), ['<CR>'] = cmp.mapping.confirm({ select = true }), }, sources = { { name = 'nvim_lsp' }, { name = 'buffer' }, } }) ```

Debug Completion With Messages

Enable completion messages:

vim
set verbosefile=/tmp/vim-completion.log
set verbose=9
" Trigger completion
<C-x><C-o>
" Check log
:e /tmp/vim-completion.log

Quick Fix Checklist

  1. 1.Enable filetype plugins: filetype plugin on
  2. 2.Check omnifunc is set: :echo &omnifunc
  3. 3.Install appropriate completion plugin for language
  4. 4.Verify plugin compiled/installed correctly
  5. 5.Configure completeopt properly
  6. 6.Install language server for LSP-based completion
  7. 7.Check Node.js version for coc.nvim
  8. 8.Verify Python support for Python completion

With these steps, your Vim completion should work reliably across all file types.