5

On my command line in Ubuntu Server 16.04.1 , I would like to bind Ctrlup/down to the bash history incremental search function. I found some posts how to do it. They involve the ~/.bashrc and ~/.inputrc files.

Strange characters appearing when I use the Ctrl and Arrow keys to navigate says this works via the .inputrc file in the home directory. Why does ctrl + left arrow not skip words? contains comments about not using .inputrc, about using .zshrc and using .bashrc. I am still too new to not be confused. I did not have any .inputrc in my fresh server install.

I do not understand those things:

  • is .inputrc the right place to put in key bindings in 16.04?
  • Is that the same for all different flavours als older version of ubunutu?
  • it is normal to have no .inputrc file in my home directory?
  • What is recommended : copy the /etc/input to home and edit or make a link in a new .inputrc and edit the file in etc?

I did not get it to work, too. I tried both copying the file from etc and rename it to .inputrc and also creating a new file in ~/ with:

touch .inputrc
nano .inputrc

The file content:

$include /etc/inputrc

Here is the what I put into the files.

# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
# ctrl up,down
"\e\e[A": history-search-backward
"\e\e[B": history-search-forward

Both do not work, Ctrl key is ignored. CTRLUp/down do not show the search and CTRLleft/right do not skip words. I think it matches the answer of the seconds post.

What could be the problem?

2 Answers 2

3

I am using Ubuntu 16.04 LTS. Putting the "mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving" into my ~/.inputrc worked for me.

It does not work to have those settings in /etc/inputrc file.

My ~/.inputrc file looks like this:

# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word

I deleted the above from the /etc/inputrc file, which (in my humble understanding) does not appear to be read by Ubuntu 16.04.

2
2

Hy ! Perhaps too late, but I post this for posterity...

Yes, it is normal to have no .inputrc in your home. Just create it. Are you sure you've reloaded the file?

Disconnecting from terminal and reconnecting, or simply use bind -f ~/.inputrc

That shall do the job...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.