Bash CTRL to move the cursor between words / lines

I use the CTRL key to move faster when using the left and right arrow keys (goes to the end of the word instead of one char at a time).

Can I do this in bash somehow?

Maybe I could encode it, but I was wondering if there was anything easier / already done.

+72
bash
Feb 17 '11 at 12:48
source share
3 answers

With the default readline key binding, ALT + B returns one word, ALT + F jumps forward one word.

Ubuntu's default setting additionally provides CTRL + arrows, as you are used to. They are located in /etc/inputrc and are listed as follows:

 # 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 don’t know why we need three of them ...

+84
Feb 17 '11 at 12:53
source share

As Thomas explained, you can add bindings to /etc/inputrc .

Another alternative, so it loads every time you log in, puts them in ~/.bashrc as follows:

 #use ctl keys to move forward and back in words bind '"\eOC":forward-word' bind '"\eOD":backward-word' 

I found out that you can use cat > /dev/null to view the characters your keyboard sends, for example, CTRL + right arrow shows:

 ^[OC 

where ^[ matches \e , so where is the code from the bind command.

You can also search for bindings as follows:

 bind -p | grep forward-word 

All of this is pretty damn cool, and I'm glad I recognized the even greater power of bash.

+39
Feb 17 2018-11-17T00:
source share

.Inputrc in your home directory will cause ctrl + left to stop working in Ubuntu (for example).

To make it work, add the following to ~ / .inputrc:

 # Include system-wide inputrc, which is ignored by default when # a user has their own .inputrc file. $include /etc/inputrc 

loan for f.kowal

0
Jul 10 '19 at 20:22
source share



All Articles