Atom编辑器:多个片段 [英] Atom Editor: multiple snippets

查看:87
本文介绍了Atom编辑器:多个片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题,但是除了自述文件外,我找不到任何文档.

This is such a simple question but I can't find any documentation besides the readme.

如何在Atom Editior中具有多个自定义片段:

How can I have multiple custom snippets in Atom Editior:

例如,我现在在我的snippets.cson中有这个

For example I have this in my snippets.cson right now

'.source.js':
  'Normal Comment Block':
    'prefix': 'cmm'
    'body': """
      //**********************************************************************************
      //
      //**********************************************************************************
    """

'.source.js':
  'Dashed Comment Block':
    'prefix': 'c--'
    'body': """
      //----------------------------------------------------------------------------------
      //
      //----------------------------------------------------------------------------------
    """

但是cmm不起作用,我只能使用snippets.cson中的最后一项.有想法该怎么解决这个吗?我想使用大约十二种不同的代码段,但我不知道如何正确地添加它们.

But cmm doesn't work, I can only use the last item in the snippets.cson. Any ideas on how to fix this? I have about a dozen different snippets I'd like to use but I cannot figure out how to include them properly.

推荐答案

配置文件格式称为CSON,即CoffeeScript对象表示法.像JSON(JavaScript对象表示法)一样,它是用于描述简单对象的文本格式.因此,当您两次指定键(例如您的示例中的.source.js)时,第二个实例将覆盖第一个实例.如果您只有一个.source.js,则一切正常:

The configuration file format is called CSON, CoffeeScript Object Notation. Like JSON (JavaScript Object Notation) it is a text format for describing simple objects. Because of which, when you specify a key twice, like .source.js in your example, the second instance overwrites the first. If you simply have one .source.js everything will work fine:

'.source.js':
  'Normal Comment Block':
    'prefix': 'cmm'
    'body': """
      //**********************************************************************************
      // $1
      //**********************************************************************************
      $0
    """
  'Dashed Comment Block':
    'prefix': 'c--'
    'body': """
      //----------------------------------------------------------------------------------
      // $1
      //----------------------------------------------------------------------------------
      $0
    """

此外,我还随意在片段中添加制表位,以便在扩展片段时,光标应首先位于注释内.您可以输入评论,然后按 TAB 退出并继续.

Additionally, I took the liberty of adding tab stops to your snippets so that when you expand the snippet, your cursor should land first inside the comment. You can enter your comment and then press TAB to exit out and continue on.

这篇关于Atom编辑器:多个片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆