Can no longer use CTRL+Left/Right in Bash Terminal

I usually use CTRL+Left and CTRL+Right to navigate between words on the command-line. I switched my laptop on this morning and can no longer do that. Instead, the CTRL+Left input code gets printed in the terminal.

Ie: Here's my output when I try to navigate with CTRL+Left:

~ $ test test ;5D;5D;5D

Curiously, I can still use CTRL+Left/Right just fine in VIM.


Solution 1:

Open ~/.inputrc file and add the following lines:

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

Close and reopen shell.Now you should be able to use those keys.

Reasons for this behavior ? Not quite certain. For some reason or the other your bash stopped reading /etc/inputrc file, but it should be reading the one in your home folder

Solution 2:

Posting this an answer for visibility, as it's better than the current answer - however the real author is @corygross who wrote it as a comment above.

Cause when you have a ~/.inputrc Ubuntu doesn't source the global /etc/inputrc

Solution: manually source /etc/inputrc in your personal ~/.inputrc

set completion-ignore-case On

$include /etc/inputrc

This is much better than re-adding all the individual bits of Ubuntu's defaults back to your personal /etc/inputrc.