开发者

MSysGit Bash - how to enable Ctrl+Left / Right arrows?

开发者 https://www.devze.com 2023-01-23 05:32 出处:网络
开发者_如何转开发Is there a way to enable Ctrl + ← / → keyboard shortcuts (go to previous / next word) in the Bash console installed with MSysGit?At your Bash prompt, press Ctrl-v Ctrl-Left-Arrow an

开发者_如何转开发Is there a way to enable Ctrl + / keyboard shortcuts (go to previous / next word) in the Bash console installed with MSysGit?


At your Bash prompt, press Ctrl-v Ctrl-Left-Arrow and Ctrl-v Ctrl-Right-Arrow and make note of the output. You should see something like: ^[OD and ^[OC or similar. Add the following lines to your ~/.inputrc:

"\eOC": forward-word
"\eOD": backward-word

where you will substitute \e for escape (^[) and the rest of the characters you got (OD, OC or similar).

To re-read the file and make the changes active immediately, press Ctrl-x Ctrl-r.


I found this answer by tan on AskUbuntu, which worked for me after none of these answers did. I'll repost it here.

What is in your ~/.inputrc and /etc/inputrc? The minimum to get those keys working is, I think:

# 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

If you have these in /etc/inputrc, the file needs to be included from ~/.inputrc, so check that it has the following line:

$include /etc/inputrc


Not really answering your question, but you can try ALT-F and ALT-B instead.


Adding to my ~/.inputrc

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

Was enough for me.


This worked for me in Windows 7:

Add this to the ~/.inputrc Then restart the console and it should work for you.

This makes it so you can do either use

CTRL+ or CTRL+

Or

ALT+ or ALT+

## Windows msysgit
## Alt + right/left
"\e\e[C": forward-word     ### Alt + right
"\e\e[D": backward-word    ### Alt + left
## Ctrl + right/left
"\e[C": forward-word       ### Ctrl + right
"\e[D": backward-word      ### Ctrl + left


For those confused on why it is not working for the ctrl+Left-Arrow and ctrl+Right-Arrow.

This is because of a bug with windows 7, maybe others, and msys where the ctrl key would not be recognized (at least for my case).

To check if you are in the same situation, do what @Dennis say:

  • Open terminal
  • Make sure ctrl+v has not been remapped to something else
  • Press ctrl+v followed by ctrl+Left-Arrow to check the key sequence
  • Look at the output

Repeat with only pressing the Left-Arrow.

If they are identical, welcome to my world. You can now use Autohotkey to remap the keys or use the newer windows git bash.


I edited the file /etc/inputrc:

      sudo gedit /etc/inputrc

and commented out the following lines:

      $if term=rxvt
      "\e[8~": end-of-line
      "\eOc": forward-word
      "\eOd": backward-word
      $endif

Then I edited the file ~/.bashrc:

      sudo gedit ~/.bashrc

and added the following lines at the bottom:

      #### enable Ctrl+Left , Ctrl+Right keybindings:
      bind '"\e[1;5C":forward-word'   # Ctrl+Right
      bind '"\e[1;5D":backward-word'  # Ctrl+Left 

It seems to work and, at least so far, without side effects.

(tested on Ubuntu GnomeShell Remix 12.04 AMD64)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号