Zsh-autosuggestions: Use Ctrl+Enter for executing current autosuggestion; Using

Created on 23 Jun 2017  Â·  5Comments  Â·  Source: zsh-users/zsh-autosuggestions

I have an issue regarding keybindings:

  • How can I replace the Up-key with Ctrl+k such that I move to the next possible suggestion with vi-like bindings?
    Unfortunately I didn't find any documentation on which keybinding I have to set to make this work.
  • How can I use Ctrl+Enter to execute the currently shown suggestion? "^M" corresponds to Enter, I don't see a way to add the Ctrl control-sequence

Thanks for help

Most helpful comment

Regarding the second part, your terminal emulator probably does not distinguish between Enter, Ctrl-Enter, and Shift-Enter. You can check this by hitting Ctrl-v Enter, Ctrl-v Ctrl-Enter... They most likely all send ^M.

One solution is to create a custom keycode. I've used iTerm to send the escape sequence [[CE, and then used the binding bindkey '^[[[CE' autosuggest-execute

In iTerm, this is done underProfile -> Keys. Click the + to add a new mapping, enter the desired key sequence, and then choose Send Escape Sequence

All 5 comments

Regarding the second part, your terminal emulator probably does not distinguish between Enter, Ctrl-Enter, and Shift-Enter. You can check this by hitting Ctrl-v Enter, Ctrl-v Ctrl-Enter... They most likely all send ^M.

One solution is to create a custom keycode. I've used iTerm to send the escape sequence [[CE, and then used the binding bindkey '^[[[CE' autosuggest-execute

In iTerm, this is done underProfile -> Keys. Click the + to add a new mapping, enter the desired key sequence, and then choose Send Escape Sequence

How can I replace the Up-key with Ctrl+k such that I move to the next possible suggestion with vi-like bindings?

This plugin doesn't support cycling through suggestions. To see what the up-key is bound to in your environment, type bindkey ', hit ctrl+v and the up arrow, then close the quote ' and hit enter. On my machine this looks like this:

% bindkey '^[[A'
"^[[A" up-line-or-history

Meaning that the up key is bound to the up-line-or-history widget. In order to bind ctrl+k to up-line-or-history, run bindkey '^K' up-line-or-history. If you want that to take effect on every zsh session going forward, add it to your .zshrc.

How can I use Ctrl+Enter to execute the currently shown suggestion? "^M" corresponds to Enter, I don't see a way to add the Ctrl control-sequence

In addition to @mattsoutherden's answer, check out a previous question here: https://github.com/zsh-users/zsh-autosuggestions/issues/154

@mattsoutherden Thank you for your previous comment about using iTerm to send an escape sequence. I'd like to learn more about this, as it's still not working as I expect. Here's the binding I set up:

screen shot 2018-10-01 at 10 15 54 am

Is it supposed to have the [[ proceeding it? It results in this mapping, which does seem to match the bindkey '^[[[CE' autosuggest-execute binding you suggest above:

screen shot 2018-10-01 at 10 17 48 am

From iTerm when I press Command+Enter I see:

➜  ~ cat -v
^[[[CE

Which I think is correct? However, when I attempt to use the binding, with autosuggestions, the suggestion is replaced with just a capital "E". For example, if I start typing "cat" into the terminal, autosuggest suggests appending -v:
screen shot 2018-10-01 at 10 19 48 am

When I press Command+Enter it then becomes:
screen shot 2018-10-01 at 10 20 39 am

I'd like to learn more about all of this. Your help would be appreciated.

this is what I have in my .zshrc and it works:

export ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
export ZSH_AUTOSUGGEST_USE_ASYNC=1
antigen bundle zsh-users/zsh-autosuggestions
bindkey '^[[[CE' autosuggest-execute

did you load the autosuggest plugin before the bindkey command? could you post your .zshrc? @bbuchalter

Sorry, not sure. I have not been able to replicate that behaviour, so I can't suggest what may be causing it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fgr0 picture fgr0  Â·  3Comments

mindyourlifeguide picture mindyourlifeguide  Â·  6Comments

raulferras picture raulferras  Â·  3Comments

Kenmmm picture Kenmmm  Â·  4Comments

glacambre picture glacambre  Â·  3Comments