0

In his A Practical Guide to Linux, 4e, Sobell gives us the following snippet:

$ cat ~/.inputrc 
set editing-mode vi 
$if mode=vi
      "\C-y": vi-next-word
   $else
      "\C-y": forward-word
$endif

The snippet arises in the context of wanting to cause CONTROL-Y to move the cursor to the beginning of the next word regardless of whether bash is in vi or emacs mode.

What I am confused about is how we can be in emacs mode at all given this snippet. My current understanding is the following:

  1. When I use some elements/shortcuts/tokens (I don't know the term) from the Readline Library, bash goes and looks in input.rc to see what I mean by it.

  2. If 1) is true (perhaps it's not and input.rc is only used on initialization of a new shell but, in that case, I can't understand why the $else clause above is relevant given that it would never be reached?) then after I use set -o emacs and, perhaps, use CONTROL-Y to skip ahead in a given entry to the command line, won't input.rc be read and switch me back to a editing-mode = vi situation?

1 Answer 1

1

I think you got it almost right.

set editing-mode will determine which Readline mode is used by default. But bash allows you to switch modes whenever you want; other applications using Readline might do so too.

Reading the actual .inputrc file every time you press a key would be inefficient, so what actually happens is probably more like:

When an program initializes the Readline library, the library will read the .inputrc file, preparing the desired settings for both modes. The set editing-mode will immediately determine which mode will be offered to the user first; but both modes will still be configured, just in case the user wants to switch modes later.

If there are no conditions, any key bindings will be applied to both modes if possible; with a $if mode= conditional construct, you can make a key binding apply to a particular mode only.

There are other conditional constructs too: $if term= can be used to configure key binding only if the current terminal is of a particular type, and $if application= can be used to make application-specific key bindings in .inputrc.

1
  • Hmm, I only slightly follow forgive me, but that is a failure on my part and not yours. It seems a strange thing for me to think about both modes being configured in parallel and "ready" in case any editing mode changes happen but, like I said, I don't know enough about Linux or OS's in general to protest :) thank you again for your help! Commented Feb 8, 2024 at 5:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.