我已经使用 Sublime Text 一段时间了(在 MacBook Pro 上),并且想让它的键击与 shell 兼容。
在 shell 中,要跳转到行首/行尾,我按 fn+Left/fn+Right。
在 Sublime Text 中,我了解如何为 fn+Left/fn+Right 设置键绑定,但是我看不到 fn 键的键名(不是 f1、f2 等功能键,我指的是标记为“fn”的键)。
如何在 Sublime Text 中完成这项工作?
我想我对自己太苛刻了。
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)
希望有帮助。
对我来说(在 MBP 上):
cmd 和 left 作为 Home
cmd 和 Right 作为 End
无需更改首选项中的任何配置。
打开菜单
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 } }
您现在可以使用以下组合:
为了在 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 } },
]
这是一个与 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(或任何应用程序)才能生效。