Search backward for :
, then delete to the end of the line: Ctrl+R :
Alt+D. Ctrl+R is the history search command, and the line you're editing is part of the history. Most commands, including Alt+D, terminate the incremental history search and have their usual effect.
In vi mode: F:C
This applies in both bash and zsh (in the default configuration, I don't guarantee that there aren't exotic combinations of options in zsh that will make it react differently, and of course this assumes the default keybindings).
The interface between a terminal application and a terminal emulator (or hardware terminal) transmits bytes, not keys. Function keys such as cursor movement keys are translated into escape sequences (beginning with the escape character ESC a.k.a. \e
a.k.a. \033
a.k.a. 0x1b a.k.a. ^[). The same goes for combinations of a function key or a character key with modifiers, though not all terminals send different sequences for all the different modifier combinations. A few keys are sent encoded as control characters (e.g. Tab → Ctrl-I = \t
= \011
).
As you can see, there are many ways to describe control characters. Some have a name, corresponding to their traditional function (e.g. Tab, Line feed); those tend to have a backslash+letter combination that you can use inside $'…'
or in an argument to echo
or print
(as well as in sed regular expressions and in string literals in awk, C and other languages (note that different tools may have a slightly different set of escape sequences)). You can use backslash+octal (e.g. \033
) in these contexts as well.
There is some variation as to which escape sequence terminals send for each key. Fortunately, there is almost no overlap: there are very few character sequences that mean different keys on different terminal. The main problem is character 127 = \177
= 0x7f which is most often Backspace nowadays but sometimes Delete.
^[OF
and ^[[F
(i.e. \eOF
and \e[F
) are the two common escape sequences sent by End. ^E
(i.e. \005
) is the Emacs key binding (Ctrl+E) for end-of-line
.
To see what your terminal emulator sends for a particular key or key combination, press Ctrl+V and then the key in question. This inserts the first character of the escape sequence literally. Escape sequences normally consist of an escape character followed by printable characters, so the rest of the escape sequence is inserted literally too.
The Terminfo database contains the escape sequences for some keys. You'll find the list of Terminfo capabilities in the terminfo(5) man page on your system. In zsh, you can list the values in the database through the terminfo
associative array. Beware when printing out values that they contain escape sequences which are also interpreted by the terminal when displayed, so print them in a quoted form.
% print -lr ${(q)terminfo[kend]}
$'\033'OF
See How do keyboard input and text output work? for a more complete overview of what happens when you press a key. It isn't necessary to understand key bindings in zsh.
Best Answer
^
in ZSH (and many other softwares; see for examplestty -a
) refers to control key e.g. for control-L to clear the screen one might find in the ZSH keybindings listI cannot comment on how
^~u
~w
^@j
in the ttscoff keybindings relate to ZSH. That software appears unrelated to ZSH; the full list of what ZSH recognizes can be found in thezshzle(1)
manual, which for some version of ZSH (do instead check the manual for the version you have and do not blindly assume that this list is correct for that version of ZSH) includesTo make the Apple command key generate codes in the terminal requires that the terminal program be configured to do so; the instructions for this will vary depending on whether you are using
Terminal.app
oriTerm.app
or something else (dig around in the preferences or check the manual).With
iTerm.app
(this may change; GUI apps tend to move things around over time) try the iTerm2 menu, Preferences, Keys, find the widget to add something, and then "send hex code"0x02
Then in ZSH
bindkey
this sequenceand now splat-shift-option-O should cause ZSH to clear the screen; instead
bindkey
your desired widget and set that in your configuration:or whatever other binding that works for you. Be sure to run
bindkey
and inspect that no other existing widget that you want to use uses the key code...