# 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:
| Shortcut | Completion 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:
:echo &omnifuncIf empty, you need to enable filetype plugins:
filetype plugin onNow check again for a specific file type:
vim myfile.py:echo &omnifuncFor 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:
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#CompleteCSSJavaScript/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:
: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:
Plug 'deoplete-plugins/deoplete-jedi'Popup Menu Not Appearing
The popup menu should appear automatically. If it doesn't:
- 1.Check completeopt:
:set completeopt?Recommended setting:
set completeopt=menuone,longest,previewmenuone: Show menu even for single matchlongest: Insert longest common textpreview: Show extra information
- 1.Check if popup is being suppressed:
:set pumheight?A very low value hides the menu. Set higher:
set pumheight=15No Completion Suggestions
If the menu appears but is empty:
- 1.Words exist in current buffer? Type some words first, then try completion.
- 2.Check complete option:
:set complete?Default includes current buffer, other buffers, and more:
set complete=.,w,b,u,t,i- 1.For file completion (
<C-x><C-f>), ensure you're in a path context:
" Start typing a path
:edit ./src/
" Press <C-x><C-f> to complete filenamesYouCompleteMe Issues
YCM requires compilation. Common issues:
" Check if YCM is loaded
:YcmDiagsIf you get "Unknown function", YCM isn't loaded.
Reinstall/compile YCM:
cd ~/.vim/plugged/YouCompleteMe
python3 install.py --allFor specific languages:
python3 install.py --ts-completer # TypeScript
python3 install.py --go-completer # Go
python3 install.py --rust-completer # Rustcoc.nvim Issues
Check coc status:
:CocInfoCommon issues:
- 1.Node.js not installed or wrong version:
node --version # Need 16.x or higher- 1.Extensions not installed:
:CocInstall coc-pyright
:CocInstall coc-tsserver
:CocInstall coc-html- 1.Language server not found:
:CocCommand languageserver.checkdeoplete Issues
Check deoplete status:
:echo deoplete#is_enabled()If 0, deoplete isn't initialized. Ensure you have:
let g:deoplete#enable_at_startup = 1Completion Too Slow
If completion lags:
- 1.Reduce sources:
" For deoplete
call deoplete#custom#option('sources', {
\ '_': ['buffer', 'file'],
\ 'python': ['jedi'],
\ })- 1.Add delay:
let g:deoplete#auto_complete_delay = 100- 1.For coc, reduce trigger length:
" In coc-settings.json
{
"suggest.minTriggerInputLength": 2
}Completion Disappearing Too Quickly
If the completion menu closes before you can use it:
set completeopt-=noselectAnd 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:
set verbosefile=/tmp/vim-completion.log
set verbose=9
" Trigger completion
<C-x><C-o>
" Check log
:e /tmp/vim-completion.logQuick Fix Checklist
- 1.Enable filetype plugins:
filetype plugin on - 2.Check omnifunc is set:
:echo &omnifunc - 3.Install appropriate completion plugin for language
- 4.Verify plugin compiled/installed correctly
- 5.Configure completeopt properly
- 6.Install language server for LSP-based completion
- 7.Check Node.js version for coc.nvim
- 8.Verify Python support for Python completion
With these steps, your Vim completion should work reliably across all file types.