• 中文输入+英文标点+快速编辑Markdown文本+Sublime+Snippet


    前提

    • 你的电脑安装了Sublime
    • 你的Sublime安装了Markdown EditMarkdown Preview两个插件(Package)。
    • 怎么安装还没写,先放一个我安装时参考的Blog

    ## 内容简介 这几天使用[Markdown](http://www.cnblogs.com/Xeonilian/p/markdown-cnblog-try.html)发现:为了输入`>".`等符号,一直在中英文之间切换。 研究了下,在`Sublime`里添加[`Snippet`](http://www.sublimetext.info/docs/en/extensibility/snippets.html "文本插入智能模块")完成快速编辑`Markdown`,不再需要在**中英文输入法之间切换**。

    Pros and Cons

    Pros:不需要再额外安装任何的软件,修改任何的设置。根据Snippet的英文说明,它还能提供替代等高级功能(还没尝试)。在 WindowsMac 系统下设置方法一致。
    ConsSnippet通过识别trigger text(设定词)来完成替换,英文单词之间需要加入空格来实现分割,所以在行中插入Snippet的时候需要额外添加空格。可以选择删,或者后面补空格,看着对称。

    什么是Snippet

    • 字面意思:一小段信息

    • Sublime官方定义:Whether you are coding or writing the next vampire best-seller, you’re likely to need certain short fragments of text again and again. Use snippets to save yourself tedious typing. Snippets are smart templates that will insert text for you and adapt it to their context. 为了省去重复输入的小模板

    • 不只是Markdown,也不只是Sublime里面有Snippet,这种替代方法是为了提高写作效率,所以写啥都能用。Sublime里面就提供了一个叫Lorem ipsum的Snippet。试了下会输出下面一段乱七八糟的文字。

      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    查了下,Lorem ipsum是拉丁文,意思是All the fact,中文里面叫乱数假文,排版的时候看文字输出效果的(wiki解释)。


    ## Sublime中的使用方法 ### 使用 1. 方法1:菜单栏点击**Tools | Snippets...**,弹出为当前语法可用的Snippet,点击需要的。 2. 方法2:输入 `触发词` 然后再按 `Tab键`。

    当你安装完 Markdown Edit之后其实已经附带了几个snippets,例如:
    mdl+Tab键 会显示 [](link) 用于插入链接。
    mdh1+Tab键 会显示 # Header Text # 用于插入一级标题。

    新建Snippet

    1. 点击Tools | Developer | New Snippet...
    2. 弹出内置的模板,是一个XML语法的文档。
    3. 修改,或者在这里粘贴文末的几个替换模式的代码。
    4. 保存。默认会保存在 User 文件夹里。
    5. 文件名的格式为 *.sublime-snippet注意后缀是识别snippet的关键。

    代码示例:以》替换 >。

    <snippet>
       <content><![CDATA[
    >
       ]]></content>
        
        <!-- 可选: 设置触发snippet的关键字 tabTrigger-->
        <tabTrigger>》</tabTrigger>
    
        <!-- 可选: 设定触发的语言环境 -->
        <scope>text.html.markdown, text.html</scope>
        
        <!-- 可选: 设定snippet在目录里显示的名字,如果不设定使用文件名 -->
        <description>quotation</description>
    
    </snippet>
    

    ## 代码核心部分说明 ### 最简部分 以下是一个snippet的**最简部分**。不关心语法是什么意思(我也不知道,傲娇脸)。 将`>`替换成你希望snippet输出的文字,即可。但是这个代码只能完成用方法1来进行替换,因为没有设定 `tabTrigger`。 ``` perl ]]> ``` >如果替换的内容另起一行需要顶头,否则前面的空格也算替换的内容。

    触发词(Trigger)

    将你希望用来触发snippet的单词放到 的位置。

        <tabTrigger>》</tabTrigger>
    

    如果只关心使用snippet优化Markdown编辑,设置完这两个部分即可。

    设置语言环境

    对于不同的语言环境有不一样的替换规则,所以可以用 scope 设某些替换规则只在Markdown文档里使用。

        <scope>text.html.markdown, text.html</scope>
    

    如何知道Sublime文档的Scope是什么?
    点击Tools | Developer | Show Scope Name...
    一开始看的例子都是python的,scope里面填的是source.python,我依葫芦画瓢改成了source.markdown,然而并没有用,后来发现一个给markdown写的,填的是text.html.markdown, text.html就跟着用了。
    Sublime在MAC里显示的scope是text.html.markdown meta.block-level.markdown markup.quote.markdown comment

    Snippet的描述

    如果设定了 description 当你点开Tools | Snippets...会看到这个描述。

        <description>quotation</description>
    

    光标位置

    Snippet可以控制替换之后的光标位置。
    例如:输入单个中文引号,替换成一对英文的引号,并让光标位置在两个引号中间。

    <snippet>
       <content><![CDATA[
    "$1"$2
       ]]></content>
        <tabTrigger>“</tabTrigger>
    </snippet>
    

    其中用 $1 $2 来表示光标停留的地方, $表示是变量,1和 2 是变量名字,用 Tab键能在各个位置之间切换。


    ## 其他解决方案 * [通过修改输入法的设置](http://weishu.me/2016/02/01/avoid-switching-keyboard-in-markdown/),貌似替代方法里`鼠须管输入法`能提供最好的体验。 * [知乎中的讨论](https://www.zhihu.com/question/26927822?sort=created)和[V2EX中的讨论](https://www.v2ex.com/t/343161)。 `Mac`里面设置快捷,还有其他的编辑系统里的快捷键都与`Snippet`的替换思想一致。 * 其实**普通的输入法**就能[设置中文输入用英文符号](https://jingyan.baidu.com/article/358570f64fffc0ce4724fc04.html "这是搜狗拼音里怎么从英文标点改回来的方法 ..."),这篇[Snippet使用介绍里面就采取了这个方法](http://www.jianshu.com/p/356bd7b2ea8e)。是的,这么做能简单解决切换问题,但是就不能输入中文的句号和逗号了。对于非强迫症患者应该是最直接的解决方法把。

    ## 几种Sublime里的Snippet替换代码 ### 1 从`——`到`__ __`:粗体或粗体斜体混用 文件名 `bold.sublime-snippet` ```perl ——
    <description>Blod</description>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.html.markdown, text.html</scope>
    
    ```

    2 从中文到英文"":超链接里面输入title

    文件名 quote-mark.sublime-snippet

    <snippet>
       <content><![CDATA[
    "$1"
       ]]></content>
        <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
        <tabTrigger>“</tabTrigger>
    
        <description> quote mark </description>
        <!-- Optional: Set a scope to limit where the snippet will trigger -->
        <scope>text.html.markdown, text.html</scope>
    </snippet>
    

    注意,引号在Mac里面没出现左右引号的问题,可是在Windows里面“ ”两个不一样,所以我在Windows里面,对左右两边都做了Snippet。

    3 从>:引用

    文件名 qoute.sublime-snippet

    <snippet>
       <content><![CDATA[>]]></content>
        <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
        <tabTrigger>》</tabTrigger>
        <!-- Optional: Set a scope to limit where the snippet will trigger -->
        <scope>text.html.markdown, text.html</scope>
        <description>quotation</description>
    </snippet>
    

    4 从·到 ` ` :文章中代码

    文件名 inline-code.sublime-snippet

    <snippet>
       <content><![CDATA[`$1`]]></content>
        <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
        <tabTrigger>·</tabTrigger>
        <!-- Optional: Set a scope to limit where the snippet will trigger -->
        <scope>text.html.markdown, text.html</scope>
        <description>inline code</description>
    </snippet>
    

    5 从11.:插入带数字的列表

    文件名 list1.sublime-snippet

    <snippet>
       <content><![CDATA[1.]]></content>
        <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
        <tabTrigger>1</tabTrigger>
        <description>numbering list</description>
        <!-- Optional: Set a scope to limit where the snippet will trigger -->
        
        <scope>text.html.markdown, text.html</scope>
    </snippet>
    

    6 从[ ]:方括号

    文件名 brace.sublime-snippet

    <snippet>
       <content><![CDATA[
    [$1]
        ]]></content>
        <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
        <tabTrigger>【</tabTrigger>
    
        <description>brace</description>
        <!-- Optional: Set a scope to limit where the snippet will trigger -->
        <scope>text.html.markdown, text.html</scope>
    </snippet>
    

    这个不常用,Sublime里面本身有插入连接的Snippet

    • 以上Snippet是在Mac里面写的,在Windows里验证了可以用。
    • 我发现非常容易把文件名输错了,所以把文件名也贴上了...

    TOP



    ----ฅ(*ΦωΦ)ฅ---- cognata ad sidera tendit...
  • 相关阅读:
    职业发展拷问——非科班出身如何才能成为一名合格程序员
    记一个神奇的Bug
    Python多维数组切片
    如何查看数组指针指向数组的所有元素
    RoboMongo命令(版本:Robo 3T 1.1.1)
    Git命令(Git版本:Linux 2.14.3)
    逐点收敛与一致收敛
    廖雪峰Python教程疑问
    The Non-Inverting Amplifier Output Resistance by Adrian S. Nastase [转载]
    2.4G无线射频通信模块nRF24L01+开发笔记(基于MSP430RF6989与STM32f0308)(1.(2)有错误,详见更正)
  • 原文地址:https://www.cnblogs.com/Xeonilian/p/Sublime-snippet-markdown-chiniese-with-english-punctuation-mark.html
Copyright © 2020-2023  润新知