Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork11
🛠 Better command line editing tools for Zsh
License
marlonrichert/zsh-edit
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Zsh Edit is a set of handy utilities for making life easier on the Zsh command line.
Tested to work with Zsh 5.8 and newer.
I recommend usingZnap or installing the plugin manually. You can alsoinstall it using any 3rd-party framework or plugin manager you like, but I won't document that here.
Aust add this to your.zshrc file:
znapsource marlonrichert/zsh-editTo update, runznap pull.
- Clone the repo:
% git clone --depth 1 https://github.com/marlonrichert/zsh-edit.git
- Source the plugin in your
.zshrcfile:source<your plugins dir>/zsh-edit/zsh-edit.plugin.zsh
- Restart your shell:
exec zsh
To update:
%cd<your plugins dir>/zsh-edit% git pull
Bind shell commands directly to keyboard shortcuts. What's more, when using these, your current command line will beleft intact.
bind'^[:''cd ..'bind'^[-''pushd -1' \'^[=''pushd +0'
List duplicate keybindings in the main keymap or another one.
bind -dbind -dM viins
List unused keybindings in the main keymap or another one.
bind -ubind -uM emacs
Look up which combination of keys could generate an escape sequence listed bybind orbindkey.
%bind -n'^[[5~''^[^[OA'"^[[5~" PageUp"^[^[OA" Alt-Up
Zsh Edit adds the keyboard shortcuts below to yourmain andemacs keymaps.
- By default, the
emacskeymap is yourmainkeymap. - However, if you use
vimode, then yourmainkeymap will be theviinskeymap.
All key bindings can be modified throughZsh'sbindkeycommand,after sourcingZsh Edit.
- Not all terminals support all key bindings.
- In some terminals, instead ofAlt, you'll have to pressEsc orCtrl[.
- In many terminals,Home,End,PgUp andPgDn scroll the terminal buffer anddon't send any keystrokes to the shell. To use these keys in the shell, you'll have to hold an additional modifierkey, usuallyShift. Refer to your terminal's documentation and/or settings for more info.
| Command | emacs keymap | main keymap | |
|---|---|---|---|
| Redo (reverse Undo) | Alt/ | ||
| Recover last line aborted withCtrlC orCtrlG | CtrlAltG | ||
| Replace all | Ctrl] | ||
| Reverse yank pop | AltY | ||
| Repeat word up | Alt. | ||
| Repeat word down | Alt, | ||
| Repeat word left | CtrlAlt- | ||
| Repeat word right | AltShift- | ||
| Backwardsubword | CtrlAltB | Ctrl← | CtrlAlt← |
| Forwardsubword | CtrlAltF | Ctrl→ | CtrlAlt→ |
| Backward shell word | AltB | Alt← | Shift← |
| Forward shell word | AltF | Alt→ | Shift→ |
| Beginning of line | CtrlA | Home | CtrlX← |
| End of line | CtrlE | End | CtrlX→ |
| Beginning of buffer | Alt< | PgUp | CtrlX↑ |
| End of buffer | Alt> | PgDn | CtrlX↓ |
| Backward delete character | ⌫ | ||
| Forward delete character | ⌦ | ||
| Backward killsubword | CtrlH | Ctrl⌫ | AltCtrl⌫ |
| Forward killsubword | CtrlAltD | Ctrl⌦ | AltCtrl⌦ |
| Backward kill shell word | CtrlW | Alt⌫ | Shift⌫ |
| Forward kill shell word | AltD | Alt⌦ | Shift⌦ |
| Backward kill line | CtrlU | CtrlShift⌫ | CtrlX⌫ |
| Forward kill line | CtrlK | CtrlShift⌦ | CtrlX⌦ |
PressCtrl] followed by two characters and each substring consisting of one ormore occurences of the first character will be replaced entirely with the second character. This isuseful, for example, if you pasted a list of files separated by line breaks into the command line,but you need them to be separated with spaces instead.
If you've just pasted something or the region is active, only the pasted or selected text isaffected. This way, you can find-and-replace selectively. Otherwise, this widget always operateson the whole command line.
Whenever you useyank (^Y inemacs),vi-put-after (p invicmd) orvi-put-after (P invicmd) to paste a kill into the command line,Zsh Edit will listthe contents of your kill ring (including the cut buffer) below your command line.
Additionally,Zsh Edit adds a new widgetreverse-yank-pop, which lets you cycle in theopposite direction. It is bound to^[Y in theemacs keymap.
Zsh's widgetsforward-word,backward-word,kill-word andbackward-kill-wordfail to stop on many of the positions that we humans see as word boundaries:
# Zsh with default WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>' moves/deletes way too much:# > > > > >% ENV_VAR=valuecommand --option-flag camelCaseWord~/dir/*.ext# < < < < <# Zsh with WORDCHARS='' is bit better, but skips punctuation clusters & doesn't find subWords:# > > > > > > > >% ENV_VAR=valuecommand --option-flag camelCaseWord~/dir/*.ext# < < < < < < < < <
Zsh Edit adds new widgets with better parsing rules that can find all the word boundaries that matter to us as humans.Additionally, it adds smarter movement: If the cursor is inside a word, it will move to the beginning or end of thatsame word, not the next one. This way, you can quickly toggle between the beginning and the end of each word.
For example:
# Zsh Edit with WORDCHARS=''# > > > > > > > > > > > > >% ENV_VAR=valuecommand --option-flag camelCaseWord~/dir/?*.ext# < < < < < < < < < < < < <
To stop a character from being treated as a subword separator, simply add it to$WORDCHARS. For example, by treating~,* and? as word characters, you can get more precise subword movement in path strings:
# Zsh Edit with WORDCHARS='~*?'# > > > > >%cd~/dir/?*.ext# < < < < <
If you don't want to change your$WORDCHARS globally, you can instead use the following:
zstyle':edit:*' word-chars'~*?'
This will change$WORDCHARS only for the widgets provided by Zsh Edit.
© 2020-2025Marlon Richert
This project is licensed under the MIT License. See theLICENSE file for details.
About
🛠 Better command line editing tools for Zsh
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.