Accepting ZSH AutoSuggestions
In my terminal, I have the ZSH shell, and the zsh-autosuggestions
package installed via:
brew install zsh-autosuggestions
And sourced with
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
This ensured that suggestions would appear, but I did not know how to accept them.
Read the Fine Manual
At this point the Usage documentation was instructive
If you press the → key (forward-char widget) or End (end-of-line widget) with the cursor at the end of the buffer, it will accept the suggestion, replacing the contents of the command line buffer with the suggestion.
Creating an alias for the right-arrow key
In order to not move my fingers off the home row too often, I have a Hyper-key set up, which maps four keys (Shift, Command, Option, Control) to CAPS_LOCK
My karabiner.json
has this rule
{
"description": "HYPER (SHIFT+COMMAND+OPTION+CONTROL) + n to right_arrow for auto-suggestions",
"manipulators": [
{
"from": {
"key_code": "n",
"modifiers": {
"mandatory": [
"left_shift",
"left_command",
"left_control",
"left_option"
],
"optional": ["any"]
}
},
"to": [{ "key_code": "right_arrow" }],
"type": "basic"
}
]
},
So now, when I see an AutoSuggestion, I just need to press CAPS_LOCK+N and I can accept it.
Auto-Execute
If you like to live dangerously, from the Key Bindings documentation, you could map
autosuggest-execute
: Accepts and executes the current suggestion.
bindkey '^ ' autosuggest-execute
This would bind ctrl + space to accept and execute the current suggestion.
Dotfiles
My n-dotfiles repository has a full .zshrc and karabiner setup in case these are helpful to you