Sublime Text:如何设置行首/行尾快捷方式以匹配 shell?

问题描述 投票:0回答:5

我已经使用 Sublime Text 一段时间了(在 MacBook Pro 上),并且想让它的键击与 shell 兼容。

在 shell 中,要跳转到行首/行尾,我按 fn+Left/fn+Right。

在 Sublime Text 中,我了解如何为 fn+Left/fn+Right 设置键绑定,但是我看不到 fn 键的键名(不是 f1、f2 等功能键,我指的是标记为“fn”的键)。

如何在 Sublime Text 中完成这项工作?

macos sublimetext2 sublimetext sublimetext3 key-bindings
5个回答
22
投票

我想我对自己太苛刻了。

  1. fn 按钮在 Sublime Text 中没有键名。
  2. fn+Left/fn+Right读作Home/End。只需映射
    home
    end
    就可以了。

具体来说:

Sublime Text | Preferences | Key Bindings - User
  • 在[]之间添加以下内容:

      { "keys": ["home"], "command": "move_to", "args": { "to": "hardbol" } },
      { "keys": ["end"], "command": "move_to", "args": { "to": "hardeol" } }
    

我是通过打开 SublimeText 控制台发现的:

ctrl+`
sublime.log_input(True)

现在,键入任何键都会显示它们的 Sublime Text 键名。 fn 没有引起响应,但是 fn+Left/fn+Right 产生了 Home/End.

sublime.log_input(False)

希望有帮助。


2
投票

对我来说(在 MBP 上):

cmdleft 作为 Home

cmdRight 作为 End

无需更改首选项中的任何配置。


2
投票

打开菜单

Sublime Text
>
Preferences
>
Key Bindings

将以下内容添加到数组中(在方括号之间

[]
):

{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
{ "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} },
{ "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true } }

您现在可以使用以下组合:

  • 转到行首:Home
  • 转到行尾:End
  • 从光标位置选择到行首:+Home
  • 从光标位置选择到行尾:+End

0
投票

为了在 Macbook Pro 上将键绑定添加到 ST4(以匹配 Windows 的 home 和 end),这有效

[
    { "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },   
    { "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
    { "keys": ["ctrl+home"], "command": "move_to", "args": {"to": "bof"} },   
    { "keys": ["ctrl+end"], "command": "move_to", "args": {"to": "eof"} },
    { "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} },
    { "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true } },
    { "keys": ["ctrl+shift+end"], "command": "move_to", "args": {"to": "eof", "extend": true} },
    { "keys": ["ctrl+shift+home"], "command": "move_to", "args": {"to": "bof", "extend": true } },
]

0
投票

这是一个与 Sublime 无关的解决方案,也可以与其他程序(包括 Chrome 等)一起使用

mkdir -p ~/Library/KeyBindings/ && touch ~/Library/KeyBindings/DefaultKeyBinding.dict

打开

~/Library/KeyBindings/DefaultKeyBinding.dict
并粘贴

{
    "\UF729"  = moveToBeginningOfLine:; // home
    "\UF72B"  = moveToEndOfLine:; // end
    "$\UF729" = moveToBeginningOfLineAndModifySelection:; // shift-home
    "$\UF72B" = moveToEndOfLineAndModifySelection:; // shift-end
}

您必须退出并重新打开 Sublime Text(或任何应用程序)才能生效。

来源:https://apple.stackexchange.com/a/16137/234304

© www.soinside.com 2019 - 2024. All rights reserved.