search: readline keybindings support
I've noticed that in search field some-or-all(?) of the readline keybindings aren't working.
E.g. none of kill-line (C-k), kill-word (M-d), unix-word-rubout (C-w), forward-char (C-f), backward-char (C-b), forward-word (M-f), backward-word (M-b), and many others work.
Given the https://github.com/walles/moor/commit/d0ed03fabcbaeeeb48a61a62ec026dc90b2ef751, does it mean that only a limited set of actions is supported in search field? In this case, are there reason to not provide full readline support? Thanks.
Refs:
- https://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html
- https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File.html
Well, moor doesn't use readline, so only what's implemented is implemented...
If you have specific key combos you use a lot, they could be considered.
If you have specific key combos you use a lot, they could be considered.
I'd say that one of the features with readline support (where readline is sort of interface between shell and the tool) is that you can redefine (rebind) action shortcuts to those that fit one's preference (including binding those that have no default keybinding assigned).
Listing some of the default actions/keybindings that are related to changing text or moving around, which fits the search field I guess (C is for Ctrl, M is for Alt which effectively is Esc sequence):
| Action | Default keybinding | Description |
|---|---|---|
kill-line |
C-k |
Kill the text from cursor to the end of the current line. |
unix-line-discard |
C-u |
Kill backward from the cursor to the beginning of the current line. |
kill-word |
M-d |
Kill from the cursor to the end of the current word. |
unix-word-rubout |
C-w |
Kill the word behind the cursor. |
forward-word |
M-f |
Move forward to the end of the next word. |
backward-word |
M-b |
Move back to the start of the current or previous word. |
transpose-chars |
C-t |
Drag the character before the cursor forward over the character at the cursor, moving the cursor forward as well. If the insertion point is at the end of the line, then this transposes the last two characters of the line. |
transpose-words |
M-t |
Drag the word before point past the word after point, moving point past that word as well. If the insertion point is at the end of the line, this transposes the last two words on the line. |
"Word" consists of the characters that are not shell metacharacters (space, tab, newline, |, &, ;, (, ), <, or >).
The "transpose" ones might be an overkill though.
Granted this is a small handful of them, I hope it won't be a burden to implement when you have a chance for that ππ» Thank you.
PS: I listed those that I do use all the time and some of them have custom keybindings assigned for convenience (though I'm good with default keybindings too).
Out of curiosity, how complex search strings do you tend to enter in moor?
As a background to my question, I'm usually below 10 chars all the time, so I personally never felt the need for anything except for very basic line editing.
I'd agree that most of the time it's a word or two to search for. Though sometimes I just paste search string that might consist of a couple of words or even sentences (e.g. when looking up full error messages in log files or text fragments in text and manual files). And the latter is the use case where I sometimes need to kill a word backward (or several words) to make search criteria less precise, or move fast from the very end to the middle of the phrase and kill an extra word (and move forward if I moved backward too many words). And sometime I just need to discard the whole line if pasted not what I wanted to, or go to a specific word and kill to the very end of the line. I believe that using these common keybindings is a key feature when you're working in a CLI (including the command line per se and text editors/pagers) and this is where the readline keybindings are very handy (and muscle memory, you know π).
PS: I do understand that you might not have enough spare time to implement what's not in use by yourself or the implementation might appear a bit of a hassle or the feature isn't quite popular among moor users, hence I'm absolutely not pushing and it's definitely up to you to decide whether moor would benefit from it and whether it's worth of it at all. Thank you.
By the way, the https://github.com/walles/moor/issues/107 is somewhat related as it is basically in regards to readline too. JFYI.
PS (in no relevance to this issue): was looking through the open issues andβ¦ I appreciate your support to Ukraine πΊπ¦