From ac3186df632fb3a10edf2128aaf940d01b411176 Mon Sep 17 00:00:00 2001 From: Tobias Witt Date: Thu, 7 Jan 2016 10:55:59 +0100 Subject: [PATCH] Add autosuggestions module The modules uses zsh-autosuggestions as an external submodule and defines useful keybindings for vi-mode. --- .gitmodules | 3 +++ modules/autosuggestions/README.md | 10 ++++++++++ .../autosuggestions/external/zsh-autosuggestions | 1 + modules/autosuggestions/init.zsh | 13 +++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 modules/autosuggestions/README.md create mode 160000 modules/autosuggestions/external/zsh-autosuggestions create mode 100644 modules/autosuggestions/init.zsh diff --git a/.gitmodules b/.gitmodules index a8a9e57a..9b5ffab6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,3 +16,6 @@ [submodule "modules/prompt/functions/pure"] path = modules/prompt/external/pure url = https://github.com/sindresorhus/pure.git +[submodule "modules/autosuggestions/external/zsh-autosuggestions"] + path = modules/autosuggestions/external/zsh-autosuggestions + url = https://github.com/tarruda/zsh-autosuggestions diff --git a/modules/autosuggestions/README.md b/modules/autosuggestions/README.md new file mode 100644 index 00000000..b4231318 --- /dev/null +++ b/modules/autosuggestions/README.md @@ -0,0 +1,10 @@ +# ZSH Autosuggestions + +This plugin enables [zsh-autosuggestions](https://github.com/tarruda/zsh-autosuggestions) and adds +vi-mode compatible keybindings. + +## Keybindings + +* `CTRL-F` is bound to `vi-forward-word`, it is equivalent to hitting `w` in vim and accepts the + suggestion word by word +* `CTRL-K` is bound to `vi-end-of-line` which effectively accepts the suggestion diff --git a/modules/autosuggestions/external/zsh-autosuggestions b/modules/autosuggestions/external/zsh-autosuggestions new file mode 160000 index 00000000..7a00bfa4 --- /dev/null +++ b/modules/autosuggestions/external/zsh-autosuggestions @@ -0,0 +1 @@ +Subproject commit 7a00bfa444fcd474bce9c56119d573afa2b51aba diff --git a/modules/autosuggestions/init.zsh b/modules/autosuggestions/init.zsh new file mode 100644 index 00000000..984e9fee --- /dev/null +++ b/modules/autosuggestions/init.zsh @@ -0,0 +1,13 @@ +source "${0:h}/external/zsh-autosuggestions/autosuggestions.zsh" || return 1 + +zle-line-init() { + zle autosuggest-start +} + +zle -N zle-line-init + +zstyle -s ':prezto:module:editor' key-bindings 'key_bindings' +if [[ "$key_bindings" == vi ]]; then + bindkey '' vi-forward-word + bindkey ' ' vi-end-of-line +fi