Sublime Text - 如何在 linux 或 windows 上获得 OSX 键盘快捷键

Sublime Text - How to get OSX keyboard shortcut on linux or windows

在 OSX 上的 Sublime Text 3 中,我可以使用键盘快捷键 "command+left/right arrow" 跳转到一行的 beginning/end,以及 "command+shift+left/right arrow"到 select 从我所在的点到该行的 beginning/end。

有没有办法分别以 "ctrl+left/right arrow" 和 "ctrl+shift+left/right arrow" 的形式在 linux 或 windows 上获得相同的快捷方式?

built-in OS X shortcuts,并且不是 Sublime 的一部分。但是,您可以通过覆盖 Ctrl/[= 的默认行为来模仿 Windows 或 Linux 上的这种行为28=]→和CtrlShift/ 使用自定义键盘映射。

默认情况下,使用Ctrl/前后移动光标,分别按单词,同时按住 Shift 允许选择。如果要更改此设置,请打开 Preferences -> Key Bindings-User 并添加以下内容:

{
    "keys": ["ctrl+right"],
    "command": "move_to", "args": {"to": "eol", "extend": false}
},
{
    "keys": ["ctrl+left"],
    "command": "move_to", "args": {"to": "bol", "extend": false}
},
{
    "keys": ["ctrl+shift+right"],
    "command": "move_to", "args": {"to": "eol", "extend": true}
},
{
    "keys": ["ctrl+shift+left"],
    "command": "move_to", "args": {"to": "bol", "extend": true}
}

如果打开文件时文件为空,请确保用左右方括号括起所有内容 [ ]。保存文件(会自动保存在正确的地方,就是[=14=下的User目录,选择Preferences -> Browse Packages...时打开的目录) ,您的新快捷方式应该会按预期工作。请注意,当您使用缩进文本时,使用 Ctrl 移动到行首会将您移动到 ​​text 在该行上,而不是在该行的第一个位置。如果您想这样做,请再次点击 Ctrl,或者在键定义中将 bol 更改为 hardbol以上。

Kinto 是我最近创建的东西,它不仅将键盘重新映射得更 mac 就像它会根据终端使用的需要更改键盘映射,并提供自定义键盘映射来处理 Cmd + 箭头键系统-宽的。您不再需要在 sublime text 中指定自定义键绑定。

最初 Kinto 不处理 Cmd + 箭头键,但这实际上是有人向我提出的第一个问题,所以我通过创建原生 xkb 键盘映射将其添加进来。

https://github.com/rbreaves/kinto

更新

Kinto 现在使用 xkeysnail 来简化重映射过程。

这是新配置文件的示例,但完整的重新映射是 Kinto 的一部分,需要来自 github 的最新 xkeysnail,而不是 repos。

# -*- coding: utf-8 -*-

import re
from xkeysnail.transform import *

terminals = ["gnome-terminal","konsole","io.elementary.terminal","terminator","sakura","guake","tilda","xterm","eterm","kitty"]
terminals = [term.casefold() for term in terminals]
termStr = "|".join(str(x) for x in terminals)

# [Conditional modmap] Change modifier keys in certain applications
define_conditional_modmap(lambda wm_class: wm_class.casefold() not in terminals,{
    # Default Mac/Win
    Key.LEFT_ALT: Key.RIGHT_CTRL,   # WinMac
    Key.LEFT_META: Key.LEFT_ALT,    # WinMac
    Key.LEFT_CTRL: Key.LEFT_META,   # WinMac
    Key.RIGHT_ALT: Key.RIGHT_CTRL,  # WinMac
    Key.RIGHT_META: Key.RIGHT_ALT,  # WinMac
    Key.RIGHT_CTRL: Key.RIGHT_META, # WinMac
})

# [Conditional modmap] Change modifier keys in certain applications
define_conditional_modmap(re.compile(termStr, re.IGNORECASE), {
    # Default Mac/Win
    Key.LEFT_ALT: Key.RIGHT_CTRL,   # WinMac
    Key.LEFT_META: Key.LEFT_ALT,    # WinMac
    Key.LEFT_CTRL: Key.LEFT_CTRL,   # WinMac
    Key.RIGHT_ALT: Key.RIGHT_CTRL,  # WinMac
    Key.RIGHT_META: Key.RIGHT_ALT,  # WinMac
    Key.RIGHT_CTRL: Key.LEFT_CTRL,  # WinMac
})

define_keymap(None,{
    # Cmd Tab - App Switching Default
    K("RC-Tab"): K("RC-F13"),                     # Default
    K("RC-Shift-Tab"): K("RC-Shift-F13"),         # Default
    K("RC-Grave"): K("RC-Shift-F13"),             # Default
    # K("RC-Tab"): K("RC-backslash"),               # Chromebook
    # K("RC-Shift-Tab"): K("RC-Shift-backslash"),   # Chromebook
    # K("RC-Grave"): K("RC-Shift-backslash"),       # Chromebook
    # In-App Tab switching
    # K("M-Tab"): K("C-Tab"),                       # Chromebook - In-App Tab switching
    # K("M-Shift-Tab"): K("C-Shift-Tab"),           # Chromebook - In-App Tab switching
    # K("M-Grave") : K("C-Shift-Tab"),              # Chromebook - In-App Tab switching
    K("Super-Tab"): K("LC-Tab"),                  # Default
    K("Super-Shift-Tab"): K("LC-Shift-Tab"),      # Default
    K("LC-Grave") : K("LC-Shift-Tab"),            # Default

    # Wordwise
    K("RC-Left"): K("Home"),                      # Beginning of Line
    K("RC-Shift-Left"): K("Shift-Home"),          # Select all to Beginning of Line
    K("RC-Right"): K("End"),                      # End of Line
    K("RC-Shift-Right"): K("Shift-End"),          # Select all to End of Line
    # K("RC-Left"): K("C-LEFT_BRACE"),              # Firefox-nw - Back
    # K("RC-Right"): K("C-RIGHT_BRACE"),            # Firefox-nw - Forward
    # K("RC-Left"): K("M-LEFT"),                    # Chrome-nw - Back
    # K("RC-Right"): K("M-RIGHT"),                  # Chrome-nw - Forward
    K("RC-Up"): K("C-Home"),                      # Beginning of File
    K("RC-Shift-Up"): K("C-Shift-Home"),          # Select all to Beginning of File
    K("RC-Down"): K("C-End"),                     # End of File
    K("RC-Shift-Down"): K("C-Shift-End"),         # Select all to End of File
    K("M-Backspace"): K("Delete"),                # Delete
    # K(""): pass_through_key,                      # cancel
    # K(""): K(""),                                 #
})

define_keymap(lambda wm_class: wm_class.casefold() not in ("code"),{
    # Wordwise remaining - for Everything but VS Code
    K("M-Left"): K("C-Left"),               # Left of Word
    K("M-Shift-Left"): K("C-Shift-Left"),   # Select Left of Word
    K("M-Right"): K("C-Right"),             # Right of Word
    K("M-Shift-Right"): K("C-Shift-Right"), # Select Right of Word
    # ** VS Code fix **
    #   Electron issue precludes normal keybinding fix.
    #   Alt menu auto-focus/toggle gets in the way.
    #
    #   refer to ./xkeysnail-config/vscode_keybindings.json
    # **
    #
    # ** Firefox fix **
    #   User will need to set "ui.key.menuAccessKeyFocuses"
    #   under about:config to false.
    #
    #   https://superuser.com/questions/770301/pentadactyl-how-to-disable-menu-bar-toggle-by-alt
    # **
    #
})

define_keymap(re.compile(termStr, re.IGNORECASE),{
    # Ctrl Tab - In App Tab Switching
    K("LC-Tab") : K("LC-PAGE_DOWN"),
    K("LC-Shift-Tab") : K("LC-PAGE_UP"),
    K("LC-Grave") : K("LC-PAGE_UP"),
    # Converts Cmd to use Ctrl-Shift
    K("RC-Tab"): K("RC-F13"),
    K("RC-Shift-Tab"): K("RC-Shift-F13"),
    K("RC-V"): K("C-Shift-V"),
    K("RC-MINUS"): K("C-Shift-MINUS"),
    K("RC-EQUAL"): K("C-Shift-EQUAL"),
    K("RC-BACKSPACE"): K("C-Shift-BACKSPACE"),
    K("RC-Q"): K("C-Shift-Q"),
    K("RC-W"): K("C-Shift-W"),
    K("RC-E"): K("C-Shift-E"),
    K("RC-R"): K("C-Shift-R"),
    K("RC-T"): K("C-Shift-t"),
    K("RC-Y"): K("C-Shift-Y"),
    K("RC-U"): K("C-Shift-U"),
    K("RC-I"): K("C-Shift-I"),
    K("RC-O"): K("C-Shift-O"),
    K("RC-P"): K("C-Shift-P"),
    K("RC-LEFT_BRACE"): K("C-Shift-LEFT_BRACE"),
    K("RC-RIGHT_BRACE"): K("C-Shift-RIGHT_BRACE"),
    K("RC-A"): K("C-Shift-A"),
    K("RC-S"): K("C-Shift-S"),
    K("RC-D"): K("C-Shift-D"),
    K("RC-F"): K("C-Shift-F"),
    K("RC-G"): K("C-Shift-G"),
    K("RC-H"): K("C-Shift-H"),
    K("RC-J"): K("C-Shift-J"),
    K("RC-K"): K("C-Shift-K"),
    K("RC-L"): K("C-Shift-L"),
    K("RC-SEMICOLON"): K("C-Shift-SEMICOLON"),
    K("RC-APOSTROPHE"): K("C-Shift-APOSTROPHE"),
    K("RC-GRAVE"): K("C-Shift-GRAVE"),
    K("RC-BACKSLASH"): K("C-Shift-BACKSLASH"),
    K("RC-Z"): K("C-Shift-Z"),
    K("RC-X"): K("C-Shift-X"),
    K("RC-C"): K("C-Shift-C"),
    K("RC-V"): K("C-Shift-V"),
    K("RC-B"): K("C-Shift-B"),
    K("RC-N"): K("C-Shift-N"),
    K("RC-M"): K("C-Shift-M"),
    K("RC-COMMA"): K("C-Shift-COMMA"),
    K("RC-DOT"): K("C-Shift-DOT"),
    K("RC-SLASH"): K("C-Shift-SLASH"),
    K("RC-KPASTERISK"): K("C-Shift-KPASTERISK"),
}, "terminals")

https://medium.com/@benreaves/kinto-a-mac-inspired-keyboard-mapping-for-linux-58f731817c0

这里还有一个要点,如果你只是想看看它的核心是什么,它不会在需要时替换你的键盘映射。 Gist 也不包括设置 macOS 样式 cursors/word-wise 使用 Cmd 和箭头键的操作的自定义 xkb 键盘映射文件。

https://gist.github.com/rbreaves/f4cf8a991eaeea893999964f5e83eebb