0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AtomでGitHub Markdownの行末にスペース二つと改行を入れるキーバインドを作った

Last updated at Posted at 2019-07-10

目的 : I want to insert two spaces and one new line to line endings in Atom Editor.

技術書典の本を書くために、AtomでGitHub Markdownを書いているのですが、行末にスペースを2個入れるのが地味にめんどくさいです。
なので、スペース2個と改行を挿入してくれるキーバインドを作りました。

方法 : I wrote two config file.

まず、Atomの設定ファイルが入っているフォルダ .atom を開きます。設定を開いて、左下に open config folder とあるので、それをクリックすると楽です。

次に、 keymap.csoninit.coffee に次のコードを追加します。

keymap.cson
'atom-text-editor':
  'ctrl-enter': 'user:hardbreak-markdown'
init.coffee
atom.commands.add 'atom-text-editor',
  'user:hardbreak-markdown': (event) ->
    editor = @getModel()
    editor.insertText("  \n")

あとはAtomを再起動するだけです。
これで、ctrl-enterでスペース2個と改行を挿入するキーバインドが作れました。

感想 : I thought.

keymap.cson のコメントに書かれているURL、 https://flight-manual.atom.io/behind-atom/sections/keymaps-in-depth/ に載っているサンプルスクリプトは罠でした。
昔は設定ファイルがJavaScriptだったのでしょうが、今はcoffeeスクリプトなため、このままでは動きません。
正解はこちら https://atom.io/docs/api/v1.38.2/CommandRegistry でした。
まぁそんな罠にはまりつつも無事に目的のキーバインドが作れたので良しとします。
技術書典の本バリバリ書くぞー!!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?