Skip to content

Commit

Permalink
Improve up/down arrow widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonrichert committed Jun 20, 2021
1 parent 80119c2 commit ff84e8d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ Works out of the box with zero configuration, but also supports `zsh-z`, `zoxide
![recent dirs](.img/recent-dirs.png)

## Key Bindings
| Key(s) | Action | <sub>[Widget](#change-other-key-bindings)</sub> |
| Key(s) | Action | <sub>[Widget](.zshrc)</sub> |
| ------ | ------ | --- |
| <kbd>Tab</kbd> | Accept top completion | <sub>`complete-word`</sub> |
| <kbd>Shift</kbd><kbd>Tab</kbd> | Accept bottom completion | <sub>`complete-word`</sub> |
| <kbd>Ctrl</kbd><kbd>Space</kbd> | Show additional completions | <sub>`list-expand`</sub> |
| <kbd>↑</kbd> | Cursor up (if able) or history menu | <sub>`up-line-or-search`</sub> |
| <kbd>↓</kbd> | Cursor down (if able) or completion menu | <sub>`down-line-or-select`</sub> |
| <kbd>Alt</kbd><kbd>↑</kbd> | Cursor up (always) | <sub>`up-line`</sub> |
| <kbd>Alt</kbd><kbd>↓</kbd> | Cursor down (always) | <sub>`down-line`</sub> |
| <kbd>PgUp</kbd> | History menu (always) | <sub>`history-search`</sub> |
| <kbd>PgDn</kbd> | Completion menu (always) | <sub>`menu-select`</sub> |
| <kbd>PgUp</kbd> / <kbd>Alt</kbd><kbd>↑</kbd> | History menu (always) | <sub>`history-search`</sub> |
| <kbd>PgDn</kbd> / <kbd>Alt</kbd><kbd>↓</kbd> | Completion menu (always) | <sub>`menu-select`</sub> |
| <kbd>Ctrl</kbd><kbd>R</kbd> | Live history search, from newest to oldest | <sub>`history-incremental-search-backward`</sub> |
| <kbd>Ctrl</kbd><kbd>S</kbd> | Live history search, from oldest to newest | <sub>`history-incremental-search-forward`</sub> |

Expand Down
16 changes: 7 additions & 9 deletions module/.autocomplete.key-binding
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,18 @@ bindkey -M viins $key[Control-Space] list-expand
bindkey -M emacs $key[Up] up-line-or-search
bindkey -M viins $key[Up] up-line-or-search

bindkey -M emacs $key[Down] down-line-or-select
bindkey -M viins $key[Down] down-line-or-select

bindkey -M emacs $key[Alt-Up] up-line
bindkey -M vicmd $key[Up] up-line

bindkey -M emacs $key[Alt-Down] down-line
bindkey -M vicmd $key[Down] down-line

bindkey -M emacs $key[Alt-Up] history-search
bindkey -M emacs $key[PageUp] history-search
bindkey -M viins $key[PageUp] history-search
bindkey -M vicmd $key[Up] history-search

bindkey -M emacs $key[Down] down-line-or-select
bindkey -M viins $key[Down] down-line-or-select

bindkey -M emacs $key[Alt-Down] menu-select
bindkey -M emacs $key[PageDown] menu-select
bindkey -M viins $key[PageDown] menu-select
bindkey -M vicmd $key[Down] menu-select

bindkey -M menuselect $key[Return] .accept-line
bindkey -M menuselect $key[Control-Space] accept-and-hold
Expand Down
6 changes: 5 additions & 1 deletion widget/.autocomplete.down-line-or-select.zle-widget
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/zsh

if [[ $RBUFFER == *$'\n'* ]]; then
if (( BUFFERLINES > 1 )); then
local -i cursor=$CURSOR
zle .down-line
(( cursor == CURSOR )) &&
zle .end-of-line
(( cursor != CURSOR ))
else
zle menu-select -w
fi
6 changes: 5 additions & 1 deletion widget/.autocomplete.up-line-or-search.zle-widget
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/zsh

if [[ $LBUFFER == *$'\n'* ]]; then
if (( BUFFERLINES > 1 )); then
local -i cursor=$CURSOR
zle .up-line
(( cursor == CURSOR )) &&
zle .beginning-of-line
(( cursor != CURSOR ))
else
zle history-search -w
fi

0 comments on commit ff84e8d

Please sign in to comment.