Autocomplete word for word
Many Vim power users will try to avoid insert mode at all costs. It’s a noble goal for sure, but impossible to avoid entirely. If you’re writing prose or notes in Vim, you’ll spend more time than most in insert mode. But there are plenty of insert mode tricks to make your life easier, including myriad ways to autocomplete words.
One such trick I use is to press
<ctrl-n> repeatedly to autocomplete several words in a row that appear somewhere in the same file. For example, suppose
Some Long Complicated Phrase appears my buffer somewhere. While in insert mode, I can type
S and then
<ctrl-x> to enter a sub mode of insert mode (see
:help _CTRL-X). This gives me access to several commands that do word completion (see
:help ins-completion). One such command is
<ctrl-n> which completes from words in the current buffer.
If I then repeat
<ctrl-x> <ctrl-n>, I can continue inserting the same words from the phrase until I’ve entered
Some Long Complicated Phrase again with just a few keystrokes.
Watch the video below for a demo. In it, I use this for two phrases:
Academy Awards and
The Bridge on the River Kwai. I simply start typing
A and then press
<ctrl-x> <ctrl-n> to complete the word,
Academy, followed by
<ctrl-x> <ctrl-n> to insert the next word,
Awards. Then I do that same thing again:
T<ctrl-x> <ctrl-n> to insert
The and then
<ctrl-x> <ctrl-n> 5 more times to insert the rest of the movie title.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?