MSysGit Bash - 如何启用 Ctrl+左/右箭头?

发布于 2024-10-01 06:17:44 字数 104 浏览 1 评论 0原文

有没有办法在随 MSysGit 安装的 Bash 控制台中启用 Ctrl + / 键盘快捷键(转到上一个/下一个单词)?

Is there a way to enable Ctrl + / keyboard shortcuts (go to previous / next word) in the Bash console installed with MSysGit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

临风闻羌笛 2024-10-08 06:17:45

添加到我的 ~/.inputrc

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

对我来说就足够了。

Adding to my ~/.inputrc

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

Was enough for me.

金橙橙 2024-10-08 06:17:45

这在 Windows 7 中对我有用:

将其添加到 ~/.inputrc
然后重新启动控制台,它应该可以为您工作。

这使得您可以使用

CTRL+CTRL+

ALT< /kbd>+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

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
混浊又暗下来 2024-10-08 06:17:45

对于那些对为什么它不适用于 ctrl+左箭头ctrl+右箭头 感到困惑的人。

这是因为 Windows 7(可能还有其他操作系统)和 msys 中的一个错误,其中 ctrl 键无法被识别(至少对于我的情况)。

要检查您是否处于相同的情况,请执行@Dennis所说的操作:

  • 打开终端
  • 确保 ctrl+v 尚未重新映射到其他内容
  • ctrl< /kbd>+v 后按 ctrl+左箭头 检查按键顺序 查看
  • 输出

仅按 重复左箭头

如果它们相同,欢迎来到我的世界。您现在可以使用 Autohotkey 重新映射按键或使用较新的 Windows git bash.

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.

长亭外,古道边 2024-10-08 06:17:45

我编辑了文件 /etc/inputrc:

      sudo gedit /etc/inputrc

并注释了以下几行:

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

然后我编辑了文件 ~/.bashrc:

      sudo gedit ~/.bashrc

并在底部添加了以下几行

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

:似乎有效,而且至少到目前为止,没有副作用。

(在 Ubuntu GnomeShell Remix 12.04 AMD64 上测试)

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)

薆情海 2024-10-08 06:17:44

在 Bash 提示符下,按 Ctrl-v Ctrl-向左箭头Ctrl-v Ctrl-右箭头 并记下输出。您应该看到类似以下内容:^[OD^[OC 或类似内容。将以下行添加到您的 ~/.inputrc 中:

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

您将在其中替换 \e 为转义符 (^[) 和其余字符你得到了(ODOC 或类似的)。

要重新读取文件并立即使更改生效,请按 Ctrl-x Ctrl-r

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.

瑶笙 2024-10-08 06:17:44

我在 AskUbuntu 上找到了 tan 的这个答案,在这些答案都不起作用之后,它对我有用。我会在这里重新发布。

您的 ~/.inputrc/etc/inputrc 中有什么?我认为,让这些键正常工作的最低限度是:

# 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

如果您在 /etc/inputrc 中有这些键,则需要将 文件包含在 ~/.inputrc 中,因此检查它是否具有以下行:

$include /etc/inputrc

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
一身骄傲 2024-10-08 06:17:44

没有真正回答您的问题,但您可以尝试 ALT-FALT-B 代替。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文