How do I complete keywords using only the current buffer as the source?
Answer
<C-x><C-n>
Explanation
<C-x><C-n> triggers keyword completion that searches only the current buffer for matches, scanning forward from the cursor. This is a sub-mode of Vim's <C-x> completion family, distinct from the plain <C-n> which consults all sources listed in the complete option (other open buffers, included files, tags, etc.).
How it works
- In insert mode, type a partial word and press
<C-x><C-n>to complete from the current buffer only (forward scan) <C-x><C-p>does the same but searches backward through the buffer- Once the menu is open,
<C-n>and<C-p>cycle through the current-buffer matches
Example
You have this function at the top of your file:
function processConnectionTimeout() {
Later in the same file you type processCo and press <C-x><C-n>:
processConnectionTimeout
Only words from the current buffer are offered, ignoring all other open files.
Tips
- Use
<C-x><C-n>when you want fast, predictable completions scoped to the file you are editing, without noise from unrelated buffers - For completion from all open buffers (the default
<C-n>behavior), omit the<C-x>prefix - Other useful
<C-x>sub-modes:<C-x><C-l>(whole lines),<C-x><C-f>(file paths),<C-x><C-]>(tags) - The full list of
<C-x>sub-modes is documented at:help ins-completion