简体   繁体   English

命令行的类似Textmate的键盘导航?

[英]Textmate-like Keyboard Navigation for the Command Line?

How do I better navigate the command line? 如何更好地导航命令行? In TextMate, I can do: 在TextMate中,我可以这样做:

  • CMD + ALT + ARROW to switch tabs CMD + ALT + ARROW切换标签

  • CMD + SHIFT + ARROW to highlight lines of text CMD + SHIFT + ARROW突出显示文本行

  • ALT + SHIFT + ARROW to highlight words ALT + SHIFT + ARROW突出显示单词

  • ALT + ARROW to jump words, etc. ALT + ARROW跳字等

How do I do this kind of stuff in the terminal? 我怎么在终端上做这种东西?

Here's a slightly more complete mapping from Mac text navigation to the default Readline keys: 这是从Mac文本导航到默认Readline键的稍微完整的映射: iTerm键映射

I set this up in the Keys pane of my iTerm2 preferences, but you should be able to make the same mappings in Terminal.app (Edit: Everything except the first two. Terminal.app only lets you pick from a few different keys) 我在iTerm2首选项的Keys窗格中进行了设置 ,但你应该可以在Terminal.app中进行相同的映射(编辑:除了前两个以外的所有内容.Terminal.app只允许你从几个不同的键中选择)

In MacOS' Terminal app, you can change your keyboard bindings; 在MacOS的终端应用程序中,您可以更改键盘绑定; go to Terminal Preferences (shortcut Cmd + , ) and navigate to the 'Keyboard' tab: 转到终端首选项(快捷键Cmd + )并导航到'键盘'选项卡:

Key => Action
control cursor left => \033b
control cursor right => \033f

etc. You can do the same thing with other emacs-style bindings. 您可以使用其他emacs样式的绑定执行相同的操作。 As far as switching tabs, that's a System Preferences > Keyboard > Keyboard Shortcuts setting; 至于切换选项卡,这是系统首选项>键盘>键盘快捷键设置; click 'Application Shortcuts' on the left side, and then click + on the right to add a new shortcut. 单击左侧的“应用程序快捷方式”,然后单击右侧的+以添加新快捷方式。 Use your desired keyboard combo and pair it with the exact menu name, which in Terminal for moving forward/backward through tabs is 'Select Next Tab' and 'Select Previous Tab' (via the Window menu in Terminal), respectively. 使用您想要的键盘组合并将其与确切的菜单名称配对,在终端中用于向前/向后移动选项卡分别是“选择下一个选项卡”和“选择上一个选项卡”(通过终端中的窗口菜单)。

Does that help? 这有帮助吗?

This is a pointer for anyone landing here looking for the equivalent tips for iTerm (as opposed to the default terminal). 这是一个指向任何登陆此处寻找iTerm等效提示的指针(与默认终端相对)。

To do the same in iTerm, go to menu "Bookmarks", "Manage Profiles", "Keyboard profiles", "Global". 要在iTerm中执行相同操作,请转到菜单“书签”,“管理配置文件”,“键盘配置文件”,“全局”。

Then add all of the shortcuts you see in the other answers here, but instead of sending text "\\033..." when creating a mapping, you simply select the action "send character sequence" and the character for the escape sequence!. 然后在此处添加您在其他答案中看到的所有快捷方式,但不是在创建映射时发送文本“\\ 033 ...”,而只需选择操作“发送字符序列”和转义序列的字符!

  • "\\033b" becomes b “\\ 033b”变为b
  • "\\033f" becomes f “\\ 033f”变为f
  • and so on. 等等。

Escape sequence example 转义序列示例

Some things can be done by editing the readline bindings (see bind -p / man bash ) but for some of the mac keyboard keys you can (or need to?) set extras up in Terminal.app's preferences. 有些事情可以通过编辑readline绑定来完成(参见bind -p / man bash ),但对于某些mac键盘键,你可以(或需要?)在Terminal.app的首选项中设置额外的内容。

For word navigation try this: 对于单词导航试试这个:

Terminal preferences -> settings -> keyboard 终端首选项 - >设置 - >键盘

add the following: 添加以下内容:

  • option cursor left \\033b (escape b) (backwards word) 选项光标左\\ 033b(转​​义b)(向后字)
  • option cursor right \\033f (escape f) (forward word) 选项光标右\\ 033f(转义f)(转发字)
  • option forward delete \\033d (escape d) (kill word) 选项转发删除\\ 033d(转义d)(杀字)

Word boundaries behave a little differently, but it's better than single character or whole line navigation, and doesn't require trading your option key for a meta key and learning a bunch of new key combos. 单词边界的行为略有不同,但它比单个字符或整行导航更好,并且不需要为元键交换选项键并学习一堆新的键组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM