Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use control keys when editing a pattern, so we can use readline's #143

Closed
jidanni opened this issue Mar 30, 2021 · 5 comments
Closed

Comments

@jidanni
Copy link

jidanni commented Mar 30, 2021

Please don't use control keys here. [less 551.]
Control keys should be for 'readline' editing of the pattern.
Currently all that still works are the arrow keys when editing a
pattern.
No other program is so control-key hungry.
Anyway, I can't use ^A to get to the beginning of the pattern due to
this. I must hold down the left arrow instead. etc.
Make you a deal: how about ^^k = ^K, ^^r = ^R, etc. I.e., allow two ASCII ^'s, and a k, to do the same thing as your current CTRL-K. OK, that might cause "no way to match a ^ at the beginning of a line". OK, then use something else.

       /pattern
              Search forward in the file for the N-th line containing the pat‐
              tern.  N defaults to 1.  The pattern is a regular expression, as
              recognized by the regular expression library  supplied  by  your
              system.   The search starts at the first line displayed (but see
              the -a and -j options, which change this).

              Certain characters are special if entered at  the  beginning  of
              the  pattern;  they modify the type of search rather than become
              part of the pattern:

              ^N or !
                     Search for lines which do NOT match the pattern.

              ^E or *
                     Search multiple files.  That is, if  the  search  reaches
                     the  END of the current file without finding a match, the
                     search continues in the next file  in  the  command  line
                     list.

              ^F or @
                     Begin  the  search at the first line of the FIRST file in
                     the command line list, regardless of  what  is  currently
                     displayed  on  the screen or the settings of the -a or -j
                     options.

              ^K     Highlight any text which matches the pattern on the  cur‐
                     rent screen, but don't move to the first match (KEEP cur‐
                     rent position).

              ^R     Don't interpret regular expression  metacharacters;  that
                     is, do a simple textual comparison.
@gwsw
Copy link
Owner

gwsw commented Mar 30, 2021

Sorry, I'm not quite understanding this. less doesn't use readline, since it's built in many environments where readline is not available. It uses control chars for the search modifiers because control chars are less likely to appear in a search pattern. There are a set of sequences starting with ESC that can be used to edit the pattern if you can't or don't want to use arrow keys and the like (eg. ESC-0 to move to start of line, ESC-l to move left, etc; see the man page or help screen for the full list).

@jidanni
Copy link
Author

jidanni commented Apr 2, 2021

All I know is perl and grep can do all those things without needing control characters to do them.

$ perldoc -f m|head -n 1
    "m/*PATTERN*/msixpodualngc"

where the "m" is optional.

And grep can do highlighting...

Anyways all I know is ^A should go to the beginning of line.

Anyways, consider allowing the readline people to use readline.

@gwsw
Copy link
Owner

gwsw commented Apr 2, 2021

You could add the commands you want to the #line-edit section of your lesskey file. For example

#line-edit
^A home

would make ^A go to the beginning of the line. See LINE EDITING SECTION in the lesskey man page for more details.

@jidanni
Copy link
Author

jidanni commented Apr 2, 2021 via email

@gwsw gwsw closed this as completed Apr 27, 2021
@meribold
Copy link

In case it'll be useful to someone else who finds this thread, here's what I ended up putting into ~/.config/lesskey to get behavior that's similar to that of programs using GNU Readline:

#line-edit
^A home
^E end
^F right
^B left
^P up
^N down
^D delete
^W word-backspace
\ed word-delete
\ef word-right

Some keys are conspicuously missing (^H, ^U, \eb). That's because they already do what I expect in the version of Less I'm currently using (643).

meribold added a commit to meribold/dotfiles that referenced this issue Jun 25, 2024
Make Less behave a bit more like programs that use GNU Readline do.

gwsw/less#143
https://en.wikipedia.org/wiki/GNU_Readline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants