132

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?

kevinarpe
  • 3,678
  • 5
  • 26
  • 31
Captain Lepton
  • 1,900
  • 3
  • 15
  • 11
  • 8
    Background *(not wrong)*. – Dennis Williamson Feb 03 '11 at 16:03
  • Is there a way to call Readline to reload the history? Like `xmonad ----recompile && xmonad --restart` for reloading XMonad? – Ehtesh Choudhury Apr 19 '12 at 00:56
  • 3
    I came here looking for how to load .inputrc with a command. http://superuser.com/q/419670/56544 – dfrankow Feb 22 '13 at 17:23
  • Simply restart Bash. – Kusalananda Jun 20 '16 at 14:16
  • @Kusalananda, it seems that you have not read the question properly "How can I reload this after editing to see the changed behaviour _without restarting my terminal program_?" – Captain Lepton Jun 21 '16 at 09:19
  • 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. – Kusalananda Jun 21 '16 at 09: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? – Captain Lepton Jun 21 '16 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. – Kusalananda Jun 21 '16 at 13:36

6 Answers6

93

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

See the Bash Reference Manual for explanation.

maxelost
  • 2,997
  • 1
  • 19
  • 8
  • 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? – Captain Lepton Feb 08 '11 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 '11 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 '18 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 '19 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 (https://superuser.com/a/1064223/201206) works. What am I doing wrong? – MrMas Oct 08 '21 at 20:25
92

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).

studgeek
  • 2,345
  • 1
  • 28
  • 28
  • 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 '19 at 09:12
  • You can call first `bind -r` to remove any keyseq. – albfan Nov 08 '20 at 09:41
25

This worked for me

bind -f ~/.inputrc

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

rofrol
  • 1,849
  • 19
  • 17
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.

  • 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 08 '20 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.

Toto
  • 17,001
  • 56
  • 30
  • 41
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
thiagowfx
  • 1,718
  • 1
  • 16
  • 17