How do I write a custom command in Atom?

耗尽温柔 提交于 2019-11-30 10:38:18

问题


I want to write a command for Atom that composes two or more pre-existing commands, like "Select Line" and then "Cut". How do I do that?


回答1:


You can add the following code to your init.coffee file:

atom.commands.add 'atom-text-editor', 'custom:cut-line', ->
  editor = atom.workspace.getActiveTextEditor()
  editor.selectLinesContainingCursors()
  editor.cutSelectedText()

You can get the code to execute from the source by searching for strings in the command palette. And once you have a command created, you can map a key to it by editing your keymap.cson file:

'atom-text-editor':
    'alt-cmd-z': 'custom:cut-line'


来源:https://stackoverflow.com/questions/24456995/how-do-i-write-a-custom-command-in-atom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!