Why is Ctrl-Arrow not working in bash on OS X?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5
--
Chapters
00:00 Why Is Ctrl-Arrow Not Working In Bash On Os X?
00:40 Answer 1 Score 3
00:51 Accepted Answer Score 17
02:16 Answer 3 Score 1
02:51 Answer 4 Score 2
03:16 Thank you
--
Full question
https://superuser.com/questions/205470/w...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#macos #bash
#avk47
ACCEPTED ANSWER
Score 17
OS X uses emacs key binding my default. This is true is virtually every application on OS X, it's rather nice. It means things like C-a and C-e are beginning/end of line. You also get the nifty backward-word-kill with M-backspace, oh, and kill-line with C-k.
This should mean that in your terminal forward/backward-word are bound to M-f and M-b, respectively (M = Meta = alt/option), however that is not the case. On OS X forward/backword-word are bound to M-→ and M-← by default.
You can alter this behavior by changing how the GNU Readline Library is configured for your account. This takes place in your ~/.inputrc
file. You can get a big list of bindable commands with man readline
as well as in the online documentation like this here..
So to answer your question, you want to remap what Readline does when it sees C-→ and C-← to do what it does on your linux server.
The syntax for a ~/.inputrc
file is pretty simple for what you want to do: key-sequence: action
.
This should be what you need to get the desired behavior:
"\e[5C": forward-word
"\e[5D": backward-word
Here's another page with additional useful bindings.
(You could probably get away with copying /etc/inputrc from your linux box to your OS X ~/.inputrc)
ANSWER 2
Score 3
put in ~/.inputrc
following lines:
"\e[5C": forward-word
"\e[5D": backward-word
ANSWER 3
Score 2
As @bhh1988 mentioned, the Mission Control configuration prevents the Ctrl-Keys working with the arrow keys in bash
. I didn't want to interfere with those shortcuts, so I use the Option (i.e. Alt) key instead. Currently on Mojave using a German keyboard (don't know if that's relevant) I put the following in .inputrc
to use Option-left-arrow and Option-right-arrow to move between words.
"\e\e[C": forward-word
"\e\e[D": backward-word
ANSWER 4
Score 1
These days it seems that the escape sequences that Ctrl-Arrows output in the terminal have changed. Here is what works for me as of today (end of 2018):
"\e[1;5C": forward-word
"\e[1;5D": backward-word
Note: you can always figure out the actual escape sequences by typing cat -v
in the Terminal, and pressing Ctrl-Left Arrow or Ctrl-Right Arrow. Here is a sample output for my own Ctrl-Left Arrow:
^[[1;5C
^[[1;5C
To translate into .inputrc
lingo, replace the escape sign ^[
with \e
and stick the result inside the double quotes.