How do I auto-complete words in insert mode without any plugins?
Answer
<C-n> / <C-p>
Explanation
Vim has a powerful built-in completion system that requires zero plugins. Pressing <C-n> in insert mode searches forward through all buffers, included files, and tags for words matching what you have typed so far. Pressing <C-p> searches backward. A popup menu appears with candidates, and you can keep pressing <C-n>/<C-p> to cycle through them.
How it works
- Start typing a word in insert mode
- Press
<C-n>to trigger keyword completion and open the popup menu <C-n>selects the next match,<C-p>selects the previous match- Press
<CR>or simply keep typing to accept the current selection - Press
<C-e>to dismiss the popup and return to what you originally typed - Press
<C-y>to accept the current selection and close the popup without inserting a trailing character
Vim scans multiple sources for completions, controlled by the complete option. By default it searches the current buffer, other open buffers, and tag files.
Example
You are editing a file that contains the variable calculateTotalRevenue. On a new line, type calc and press <C-n>:
calculateTotalRevenue
Vim finds the match and inserts it. If there are multiple matches (e.g., calculateTax, calculateDiscount), a popup menu appears and you cycle through them with <C-n> and <C-p>.
Specialized completion modes
Vim offers targeted completion with <C-x> followed by a second key:
<C-x><C-l> Line completion (match entire lines)
<C-x><C-f> Filename completion
<C-x><C-]> Tag completion
<C-x><C-k> Dictionary completion
<C-x><C-o> Omni completion (language-aware)
<C-x><C-n> Current buffer keywords only
Tips
<C-n>pulls from all sources incomplete;<C-x><C-n>restricts to the current buffer only — use the latter when you have many buffers open and want faster, more relevant results<C-x><C-f>is invaluable for completing file paths while typing import statements or shell commands<C-x><C-l>completes entire lines — perfect for duplicating similar lines like struct fields or test assertions- Set
completeopt=menu,menuone,noselectfor a smoother popup experience: show the menu even with one match and don't auto-select the first entry - The popup menu supports fuzzy-ish matching — if you type
cTR,<C-n>may still findcalculateTotalRevenuedepending on yourcompletesettings - Omni completion (
<C-x><C-o>) provides language-aware completions when a filetype plugin defines anomnifunc— this works out of the box for HTML, CSS, JavaScript, Python, and many other languages - You never leave insert mode during completion — this is faster than switching to normal mode to yank and paste