zsh-edit
zsh-edit copied to clipboard
🛠 Better command line editing tools for Zsh
Zsh-Edit
Zsh-Edit is a set of powerful extensions to the Zsh command line editor.
Requirements
- Recommended: Zsh 5.7.1 or newer
- Minimum: Zsh 5.4.2
bind
Command
# Bind shell commands directly to keyboard shortcuts.
# What's more, when using these, your current command line will be left intact.
bind \
'^[c' 'code .' \
'^[o' 'open .' \
'^[l' 'git log' \
'^[s' 'git status -Mu --show-stash'
# List duplicate keybindings in the main keymap or another one:
bind -d
bind -dM viins
# List unused keybindings in the main keymap or another one:
bind -u
bind -uM emacs
# Look up the names of key codes listed by `bind` and `bindkey`:
% bind -n '^[[5~' '^[^[OA'
PreviousPage Alt-UpArrow
Key Bindings
Zsh-Edit adds the following keyboard shortcuts to keymaps main
and emacs
(which are usually
the same).
- You can customize these with Zsh's
bindkey
command, after sourcing Zsh-Edit. - Not all terminals support all key bindings.
Command | emacs |
main |
|
---|---|---|---|
Redo (reverse Undo) | Alt/ | ||
Reverse yank pop | AltY | ||
cd to parent dir |
ShiftAlt; | ||
cd to previous dir |
Alt- | ||
cd to next dir |
Alt= | ||
Select from previous 16 dirs | Alt` | ||
Select from next 16 dirs | ShiftAlt` | ||
Repeat word up | Alt. | ||
Repeat word down | Alt, | ||
Repeat word left | AltCtrl- | ||
Repeat word right | AltShift- | ||
Backward subword | AltB | Ctrl← | Alt← |
Backward shell word | CtrlAltB | Ctrl↑ | Alt↑ |
Forward subword | AltF | Ctrl→ | Alt→ |
Forward shell word | CtrlAltF | Ctrl↓ | Alt↓ |
Backward delete character | ⌫ | ||
Forward delete character | ⌦ | ||
Backward kill subword | CtrlH | Ctrl⌫ | Alt⌫ |
Backward kill shell word | CtrlW | ShiftCtrl⌫ | CtrlAlt⌫ |
Forward kill subword | AltD | Ctrl⌦ | Alt⌦ |
Forward kill shell word | CtrlAltD | ShiftCtrl⌦ | CtrlAlt⌦ |
Beginning of line | CtrlA | Home | |
End of line | CtrlE | End | |
Beginning of buffer | Alt< | CtrlHome | PageUp |
End of buffer | Alt> | CtrlEnd | PageDn |
Backward kill line | CtrlU | ShiftHome | Shift← |
Forward kill line | CtrlK | ShiftEnd | Shift→ |
Clipboard Viewer
Whenever you use yank (^Y
in emacs
), vi-put-after (p
in vicmd
) or
vi-put-after (P
in vicmd
) to paste a kill into the command line, Zsh-Edit will list
the contents of your kill ring (including the cut buffer) below your command line. In addition,
Zsh-Edit eliminates all duplicate kills from your kill ring. Thus, each entry listed is guaranteed
to be unique.
Furthermore, after pasting, when you use yank-pop (^[y
in emacs
), Zsh-Edit will show
you which kill is currently selected, making it easier to cycle to the right one. To view your
clipboard at any time – without modifying your command line – just press yank-pop by
itself.
Finally, Zsh-Edit adds a new widget reverse-yank-pop, which lets you cycle in the
opposite direction. It is bound to ^[Y
in the main
keymap.
Subword Movement
Zsh's widgets forward-word, backward-word, kill-word and backward-kill-word fail to stop on many of the positions that we humans see as word boundaries:
# Zsh default word boundaries 😕
# With default WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>'
# > > > > > > > > >
% dscl . -read ~/ UserShell; git config --get status.showUntrackedFiles
# < < < < < < < < <
# Skips/deletes _way_ too much.
# With WORDCHARS=''
# > > > > > > > >
% dscl . -read ~/ UserShell; git config --get status.showUntrackedFiles
# < < < < < < < <
# A bit better, but skips _all_ punctuation clusters & doesn't find SubWords.
Zsh-Edit adds new widgets with better parsing rules that can find all the word boundaries that matter to us as humans:
# Word boundaries with Zsh-Edit 🤗
# With default WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>'
# > > > > > > > > > > > > > >
% dscl . -read ~/ UserShell; git config --get status.showUntrackedFiles
# < < < < < < < < < < < < < <
# With WORDCHARS=''
# > > > > > > > > > > > > > > > >
% dscl . -read ~/ UserShell; git config --get status.showUntrackedFiles
# < < < < < < < < < < < < < < < <
If you don't want to change your $WORDCHARS
globally, you can instead use
zstyle ':edit:*' word-chars '*?\'
This will change $WORDCHARS
only for the widgets provided by zsh-edit
.
Author
© 2020-2021 Marlon Richert
License
This project is licensed under the MIT License. See the LICENSE file for details.