Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a custom command in Atom?

Tags:

atom-editor

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?

like image 736
Lee Avatar asked Jun 27 '14 16:06

Lee


1 Answers

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'
like image 200
Lee Avatar answered Nov 16 '22 11:11

Lee