Hacker News new | ask | show | jobs
by axkdev 703 days ago
I'd like to point out that, for example, Ctrl+a is not specific to bash, it's a readline[0] keybinding. A subset of those will work in the text box in which I am typing this comment. C-f and C-b work, even C-h, but not C-w. Perhaps this key combo is reserved for closing the firefox tab on windows? Anyway, I love readline and wish it would work on literally all text inputs.

0. https://en.wikipedia.org/wiki/GNU_Readline

3 comments

Some points worth clarifying:

- Readline is not used in every text field by default. Rather, e.g. MacOS and Readline independently offer a subset of the Emacs keybindings by default (Emacs predates Readline by many years, and I believe Ksh was the first shell to start adding some Emacs bindings to its CLI).

- Many modern CLI apps don’t use Readline, although many of them imitate the default Readline keybindings. Notably, Zsh, Fish, and IPython all use their own line editors that are clearly Readline-inspired but still different. (IPython used to use Readline, but dropped it 5-6 years ago.)

- As other commenters mention, Readline keybindings can be changed: You can switch to Vi keybindings if you want, or define your own in .inputrc. But note that those settings only affect apps that actually use Readline under the hood, so e.g. Zsh and IPython require different settings.

Hear the gospel:

    $ set -o vi
POSIX specifically calls out "set -o vi" for any and all compliant shells.

The .inputrc is specific to readline, and will not be honored by libedit (used extensively on MacOS and BSD-centric systems).

"vi: Allow shell command line editing using the built-in vi editor. Enabling vi mode shall disable any other command line editing mode provided as an implementation extension. It need not be possible to set vi mode on for certain block-mode terminals."

The standard does not specify an emacs option.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...

Bash uses readline, so setting it in .inputrc would be sufficient for bash, but it will also get applied to other apps using readline like gdb. Setting an .inputrc also allows you to configure other niceties like colored-completion-prefix and colored-stats [0].

There's certainly no harm in doing both 'set -o vi' in shell rc and 'set editing-mode vi' in .inputrc

[0]: https://wiki.archlinux.org/title/Readline#Colorized_completi...

Well, the impact of .inputrc is going to hit anything else linked with it.

Your Postgres psql client will switch to vi mode, which might not be what you intended.

And if a day comes that dash gets linked to libedit on Debian/Ubuntu, only the POSIX standard command will have the desired effect.

Better still, /etc/inputrc

The three lines that go in the top of /etc/inputrc on my boxes:

    set completion-ignore-case on
    set editing-mode vi
    set keymap vi-command
For completion, I also set the following in the bottom of /etc/bash.bashrc

    export EDITOR=vi
    set -o vi
TIL
See also: Entering text in the terminal is complicated (https://jvns.ca/blog/2024/07/08/readline/) — being able to diagnose what's going on makes the command line feel a more predictable and less chaotic