Quantcast
Channel: User Kamil Maciorowski - Super User
Viewing all articles
Browse latest Browse all 837

Answer by Kamil Maciorowski for "set editing-mode vi" vs "set -o vi" What is the difference?

$
0
0

Interactive Bash uses the Readline library to read command lines. Programs other than Bash can use the library as well. The library is designed to interactively read a command (or anything) from a user, with quite advanced line editing, key bindings, history and such.

.inputrc is the default file to customize Readline. Any program (including Bash) that uses Readline will be affected by what you put in the file (unless Readline uses another file; there are ways to customize). set editing-mode vi in .inputrc configures Readline directly.

.bashrc is the default file to customize Bash. It can be used to run anything and to configure Bash itself, including Readline used by Bash; but not Readline used by other programs. set -o vi enables vi mode in command line editing in a shell. In general POSIX mandates set -o vi, but it does not force shells to use Readline. Only because Bash does use Readline, set -o vi in Bash has anything to do with Readline. Bash implementsset -o vi by configuring Readline it uses. In Bash set -o vi is an indirect way to tell Readline used by Bash to set its editing-mode to vi.

(There is yet another way: the bind builtin in Bash is the interface to Readline, you can give it a command Readline understands, e.g. the command in question. The relevant command for Bash will be bind 'set editing-mode vi'. This is a command for Bash that explicitly uses a command for Readline.)

The two methods you discovered give you the same result in Bash. For other programs using Readline, .inputrc matters and .bashrc doesn't. And any such program may or may not support its own rc or config file designed to configure the program itself and possibly (indirectly) Readline used by it, like Bash does with .bashrc.

If Bash is about to use Readline and to parse .bashrc then Readline will read .inputrc before .bashrc gets parsed. This means if there are conflicting settings for Readline in the two files, the setting(s) from .bashrc will reconfigure Readline last, so they will win.


Viewing all articles
Browse latest Browse all 837

Trending Articles