18

I have this ~/.inputrc file that I created for certain key bindings.

# 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

whenever I try to run source ~/.inputrc, it gives me the following error:

\e[1;5C:forward-word: Command not found. \e[1;5D:backward-word: Command not found. \e[5C:forward-word: Command not found. \e[5D:backward-word: Command not found. \e\e[C:forward-word: Command not found. \e\e[D:backward-word: Command not found.

It also doesn't work when I open a new terminal, I don't get the error but my ctrl key combinations are not working in new terminal as well. I created this file myself since I do not have root access to change /etc/inputrc. Can anybody help me out? Thanks.

EDIT: I've tried the file with space after the colon (:) sign as well. It doesn't work. I also tried my making it executable (chmod +x ~/.inputrc), didn't work.

EDIT: I realized that this procedure is only for 'bash' and I am running 'tcsh'. For 'csh', use .bindings file instead of .inputrc file and use bindkey syntax.

Mikel
  • 57,299
  • 15
  • 134
  • 153

3 Answers3

16

For bash, this will reload now the currently defined mappings

bind -f  ~/.inputrc
drmuelr
  • 103
  • 4
Paul
  • 319
7

The .inputrc file is not a file to be sourced. It should be taken into account automatically by bash or other software using the readline library. If this doesn't work, add a space after the colon, e.g.

"\e[1;5C": forward-word

(I've always seen a space in this config file).

vinc17
  • 12,174
  • 1
    +1 Emphasis on "other software using the readline library". .inputrc is not a shell script; it's a readline configuration file. – chepner Sep 02 '14 at 20:04
  • Actually, that's how I had it first and I changed it to without space just to try it out. It doesn't work either way. I've added that in the edit. Thanks. – rrlamichhane Sep 02 '14 at 21:36
7

The key bindings and ~/.inputrc file posted in question is for bash. For csh (or tcsh) use a file ~/.bindings and use following syntax.

bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word

Realized this after some googling.

Mikel
  • 57,299
  • 15
  • 134
  • 153
  • 2
    For whatever reason, my tsch was ignoring the .bindings file. Adding source ~/.bindings to my ~/.cshrc file fixed this. – drmuelr Jun 07 '18 at 18:18
  • @drmuelr, if you need to do a source, you may as well have called the file .bindkeys (or any other name as a matter of fact). I have the same issue as that my tcsh (version 6.17 does not automatically source the .bindings file). Maybe @rrlamichhane can comment on what tcsh version he is using ? – Kiteloopdesign Oct 10 '22 at 11:20