inspired by: https://stackoverflow.com/questions/5407916/zsh-zle-shift-selection/68987551#68987551
This script enables copy pasting, selection etc. of text as you know it from editors. The script executes 3 steps:
- set variables to represent terminal signals (keys)
- register zle widgets (functions)
- bind widgets to keys (call functions on signals)
To use it:
- Add this file to
$ZSH_CUSTOM/plugins/keybindings
. - Make sure all the keys are defined as described below.
If not, use import the
zsh-selection.itermkeymap.json
in iTerm2. iTerm2 > Settings > Profiles > Keys > Key Mappings > Presets > Import
These variables represent the terminal signals (keys). They might differ for you. View your variables:
- run
$ cat
- enter the key combinations If you are using iTerm2, you can set signals manually with:
- go to: iTerm2 > Settings > Profiles > Keys > Key Mappings
- record the keyboard shortcut
- select action "Send escape seuqence"
- enter the escape sequence without leading
^[
Terminfo is a database that describes terminals.
It stores some of the default signals and can be accessed through predefined cap names (short names).
You can print the existing cap names with $ infocmp -1
.
zle (zsh command line editor) enables you to add stuff to your command line.
It comes with the concept of widgets (functions) that can be bound to terminal signals.
To create a new widget, run: $ zle -N WIDGET_NAME FUNCTION
.
To list all manually created widgets, run: $ zle -l
.
To list all widgets (including those from system), run: $ zle -l -a
.
Bind the keys (defined above) to widgets with bindkey KEY WIDGET
.