137

Background

I have heard that the readline module is reading ~/.inputrc and that is how it changes the behaviour of keystrokes under programs such as bash.

Question

How can I reload this after editing to see the changed behaviour without restarting my terminal program?

8
  • 8
    Background (not wrong). Feb 3, 2011 at 16:03
  • 3
    I came here looking for how to load .inputrc with a command. superuser.com/q/419670/56544
    – dfrankow
    Feb 22, 2013 at 17:23
  • 1
    @CaptainLepton I saw that. The terminal is not the same as the shell. Doing exec bash in a Bash session will replace the current shell session with a new Bash session. xterm is a terminal. Jun 21, 2016 at 9:22
  • 1
    @Kusalananda Thanks for the clarification. That is a good idea. Would you perhaps describe running > exec bash as running a new shell in the current terminal rather than restarting bash, as you are replacing your previous executable? Jun 21, 2016 at 13:25
  • 1
    Yes, there is no way of "restarting" the current shell session. This is one way of doing it. Using the solution that @maxelost gave is another. Jun 21, 2016 at 13:36

6 Answers 6

97

By default, C-x C-r is bound to re-read-init-file.

See the Bash Reference Manual for explanation.

5
  • 5
    This doesn't work for me. I tried a different mapping in the .inputrc file and also no luck: "\eX\eR": re-read-init-file Any suggestions? Feb 8, 2011 at 12:36
  • 6
    @Captain Actually, it does, except it does not clear keystrokes that were deleted in the meantime. If you e.g. add some, they are loaded. Your only solution for these is a new bash -l (shell that behaves like a login shell) that is freshly initialized.
    – Daniel Beck
    Apr 25, 2011 at 10:45
  • I was editing /etc/inputrc but I had an almost empty ~/.inputrc that was preventing the one in /etc/ from being used. Removing ~/.inputrc caused it to read /etc/inputrc and make my changes active.
    – Malvineous
    Mar 23, 2018 at 10:06
  • 1
    @Malvineous I've been caught out by that before.. if you add $include /etc/inputrc to the top of ~/.inputrc, it avoids this problem.
    – mwfearnley
    Jan 19, 2019 at 12:59
  • 1
    This doesn't work for me: bash --version reports GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu). I'm using Ubuntu 20.04 running bash in Gnome terminal 3.36.2. I checked bind -P and the keystroke is listed but running CTRL-x CTRL-r doesn't reread the file. On the other hand following answer by @studgeek (superuser.com/a/1064223/201206) works. What am I doing wrong?
    – MrMas
    Oct 8, 2021 at 20:25
95

You can also reload new entries from command line using bind -f ~/.inputrc. That will load the entries in .inputrc. Note that it just does a load, not a "reload" - so it doesn't reset any lines you happen to have removed from the .inputrc.

To quickly test from a clean slate, just run bash then work inside that new nested shell (or start a new terminal).

2
  • 1
    I see, correct me if I'm wrong, that bind -f only really accepts a filename, and not a file, so something like bind -f <(echo 'one line with ~/.inputrc syntax') (or, trivially, bind -f <(cat ~/.inputrc)) will not work. This is a bit annoying. Do you know what could I do in this respect?
    – Enlico
    Oct 13, 2019 at 9:12
  • You can call first bind -r to remove any keyseq.
    – albfan
    Nov 8, 2020 at 9:41
27

This worked for me

bind -f ~/.inputrc

https://unix.stackexchange.com/questions/153357/inputrc-file-not-sourcing-correctly/246422#246422

13

In .inputrc first choose your binding and after bind the re-read-init-file function:

set editing-mode vi
"\C-x\C-r": re-read-init-file

Press CTRL and x, release both, press CTRL and r.

1
  • This only works during initialization, i.e. for the editing mode you start the session with. If after this you change the edtiing-mode to emacs, then you won't get the keybinding. And AFAIK you need to fallback to the bind -f method.
    – Atralb
    Jun 8, 2020 at 23:13
1

This worked for me:

exec $SHELL

This runs the current shell again, without creating a subprocess, and it involves doing all the usual initialisations and script reading, so any new or changed settings in /etc/inputrc, ~/.profile, ~/.bashrc etc. become effective.

0

The following snippet for ~/.inputrc will map C-x C-r in all keymaps (emacs, vim command mode and vim insert mode):

set keymap emacs
"\C-x\C-r": re-read-init-file

set keymap vi-command
"\C-x\C-r": re-read-init-file

set keymap vi-insert
"\C-x\C-r": re-read-init-file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .