LoginSignup
10
9

More than 5 years have passed since last update.

emmetのスニペット作成:$のエスケープ

Posted at

VimにEmmetをインストールしたので、試しに以下のようなスニペットを作っていた。

.vimrc
let g:user_emmet_settings = { 
\    'javascript' : { 
\        'snippets'   : { 
\            'jq' : "$(function() {\n\t${cursor}${child}\n});"
\        }   
\    }   
\}

jQueryの

$(function() {
});

を一発で入力してくれるスニペットなのだが、ドル記号がうまく入力されない。
具体的には'$'ではなく数字の'1'が入力されてしまう。'\$'などとしてもエスケープできない。

少し調べてみたら以下のページに書いてあった。
https://github.com/emmetio/emmet/issues/95

.vimrc
let g:user_emmet_settings = { 
\    'lang' : 'ja',
\    'javascript' : { 
\        'snippets'   : { 
\            'jq' : "\\$(function() {\n\t${cursor}${child}\n});"
\        }   
\    }   
\}

'$'をエスケープする時はバックスラッシュを2つ付ければ良いらしい。

10
9
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
10
9