V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
jakezhu
V2EX  ›  问与答

如何设置 Sublime Text 2 选中代码后键入 markdown 的```自动括起代码,而不是替换

  •  
  •   jakezhu · 2017-03-15 09:58:26 +08:00 · 934 次点击
    这是一个创建于 2624 天前的主题,其中的信息可能已经有所发展或是发生改变。
    像双引号,括号,大括号之类的字符,比如选中
    v2ex ,键入双引号,变为
    "v2ex"

    那么如何设置选中 v2ex ,键入```之后,变为
    ```
    v2ex
    ```
    第 1 条附言  ·  2017-03-15 10:54:29 +08:00

    已解决。 打开Preferences -> Key Bindings - User,加入

    [
    { "keys": ["`"], "command": "insert_snippet", "args": {"contents": "```\n$0\n```"}, "context":
        [
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|;|\\}|$)", "match_all": true },
            { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
    
        ]
    },
    { "keys": ["`"], "command": "insert_snippet", "args": {"contents": "```\n${0:$SELECTION}\n```"}, "context":
        [
            { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
            { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
        ]
    },
    { "keys": ["`"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
        [
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^\\```", "match_all": true },
            { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
        ]
    }
    ]
    
    

    当选中v2ex时,键入`,将变为:

    ```
    v2ex
    ```

    参考http://stackoverflow.com/questions/16025592/custom-bracket-auto-closing-in-sublime-text

    1 条回复    2017-03-15 10:50:30 +08:00
    x13945
        1
    x13945  
       2017-03-15 10:50:30 +08:00   ❤️ 1
    markdownediting
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1778 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:41 · PVG 00:41 · LAX 09:41 · JFK 12:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.