In Evil mode, in the Normal state, with the evil-search-module variable set to Evil interactive search, I would like to use some kind of auto-completion functionality like Ctrl+n or Ctrl+p so that I don't have to type the full string I am searching for. For example, if I wanted to turn the line

foo bar grue


foo bar zork

I would like to be able to do something like this:

  1. Type :s/g
  2. Hit Ctrl+n (or some other concise key/combo).
  3. See the command prompt change to :s/grue.
  4. Type /zork<RET>.

The steps I've given above fail at step 2. At that point, instead of using the next match, Evil outputs the error message, "No later matching history item".

I have also tried using the suggestions given as answers here, but these do not work either:

  • Hitting Ctrl+f while in the middle of entering a substitution command simply causes Emacs to output the message "End of buffer".

  • Using q:is/g<Ctrl+n> causes Emacs to output the error message "No dynamic expansion for `s/g' found".

What can I do to overcome or work around this?

Update: see Evil bug #166, which refers to this issue.

  • I'm not sure how Evil's command mode works, but maybe try using hippie-expand. Many people bind it to M-/. – nanny Aug 12 '15 at 19:25
  • @nanny, Thanks for the suggestion. Hitting M-/ while in the middle of typing a substitution command causes Emacs to output "Scanning for dabbrevs...done", but doesn't complete the search string. If I instead attempt to type M-x hippie-expand<RET> in the middle of typing a substitution, Emacs instead outputs, "Command attempted to use minibuffer while in minibuffer". – sampablokuper Aug 12 '15 at 19:32
  • It's not bound to M-/ by default (it's not bound to anything). It was a suggestion. Additionally, as you've found, you cannot use M-x while in the minibuffer, you must bind functions to keys if you want to use them. – nanny Aug 12 '15 at 19:44
  • @nanny, thanks again. I haven't tried to use hippie-expand before, sorry. I've now added (global-set-key (kbd "M-/") 'hippie-expand) to my .emacs, and added the setq given here, and restarted Emacs. However, now when I hit M-/ while in the middle of typing a substitution command, Emacs outputs "No expansion found", even if the string I am typing is an initial substring of a string further on in the file. Perhaps I'm missing something... – sampablokuper Aug 12 '15 at 19:57
  • It may be some quirk with Evil's command mode, because it works for me when using the minibuffer during eval-expression (M-:) – nanny Aug 12 '15 at 20:02

You can use q/ or q:, then you'll be able to complete using cross buffer completion with auto-complete or company, if you have them configured.

To configure company for that, you need to add the backends company-dabbrev-code and/or company-dabbrev to company-backends. Then invoking company-complete should bring the completion.

enter image description here

| improve this answer | |
  • Thanks! I've upvoted, but haven't yet tried auto-complete or company, so can't yet confirm that this works for me. Will try to remember to mark it as "correct" once I have, assuming Evil bug #166 still stands. – sampablokuper Aug 21 '15 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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