LoginSignup
15
14

More than 5 years have passed since last update.

atom snippet packageの使い方

Last updated at Posted at 2014-11-14

snippetのREADMEの翻訳っぽいもの.

Snippet package

tabを入力すると,直前に入力しているプリフィックスにマッチするスニペットが展開されます.

Atom > Open Your Snippets メニューを選択するとスニペットの追加が行えます.

Snippet Format

スニペットはパッケージの snippets/フォルダに保存されています.
また.atom/snippets.csonからも読み込まれます.

スニペットファイルは.json, .csonのどちらかで作成できます.

'.source.js':
  'console.log':
    'prefix': 'log'
    'body': 'console.log(${1:"crash"});$2'

トップレベルのキー(.source.js)はスニペットが適用されるセレクタです.
次のインデントのキー(.console.log)はスニペットの名前です.

各スニペットには

  • prefix スニペットを展開するときに指定するプリフィックス
  • body スニペット本文を指定します.

あとで訳す

$ followed by a number are the tabs stops which can be cycled between by pressing tab once a snippet has been triggered.

The above example adds a log snippet to JavaScript files that would expand to.

console.log("crash");
The string "crash" would be initially selected and pressing tab again would place the cursor after the ;

複数行のbody

"""で囲みます.

'.source.js':
  'if, else if, else':
    'prefix': 'ieie'
    'body': """
      if (${1:true}) {
        $2
      } else if (${3:false}) {
        $4
      } else {
        $5
      }
    """

(以下は翻訳ではありません.)

変数も使えます.


HEADER = 
  'prefix': 'header'
  'body'  : """
   ## @author kazup0n(@kazup0n)
   ## all rights reserved.
   """

'.source.coffee':
  'header': HEADER

'source.rb':
  'header': HEADER

15
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14