11

Usually insert mode completion (<C-n>) inserts the right word the first time I press <C-n>, but not always. Therefore, I would like Vim to insert the match it deems best when I press <C-n>, but still allow me to cancel this insertion afterwards should the correct match not show up or be a long way down the list.

Of course I could code this behavior, but I have a feeling there should be a standard key(-combination) to do this. Could someone point me in the right direction?

Bonus question: is there another key I can use to get the longest match (as it was before I hit <C-n>)?

For what it's worth, I'm using completeopt=menu

3
  • 1
    Is ctrl-u what you are looking for?
    – statox
    Dec 22, 2016 at 10:11
  • No, ctrl-u seems to delete the entire line. I am looking for a combination that only removes the text that was inserted by pressing ctrl-n.
    – Octaviour
    Dec 22, 2016 at 10:39
  • My first thought was "doesn't c-g the usual cancel key work here?", then I realised that was emacs. Just a few days of learning years ago has corrupted me, I shall bathe in a sacred river and purify myself!
    – Sundar R
    Dec 22, 2016 at 17:24

1 Answer 1

17
+50

From :h complete_CTRL-E:

                                                        *complete_CTRL-E*
When completion is active you can use CTRL-E to stop it and go back to the
originally typed text.  The CTRL-E will not be inserted.

Also if you, say, type a then ^Pand you get a very long list, you can hit ^N to return to your original text with the completion popup still active. You can then type extra characters to narrow the completion list.

3
  • That was precisely what I was looking for. I had not realized that ctrl-p would also take me back to the original input. Thanks.
    – Octaviour
    Dec 22, 2016 at 11:00
  • 2
    @Octaviour, I find ctrl-p to generally be more useful than ctrl-n, because it searches for the closest match before (instead of after) where you are. So, if you have just written a word, ctrl-p would quickly show you the same word if you need to repeat it (for example using the same variable again in the code)
    – Shahbaz
    Jan 7, 2017 at 17:20
  • Yeah, I wrote ^P out of habit for exactly that reason.
    – Antony
    Jan 7, 2017 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.