Add semi-colon at end of line and return?


Is there a shortcut or package that will move the cursor to the end of the current line, type a semi-colon and return?


Not that I know of off the top of my head, but it shouldn’t be too hard to create one. You could even do it as part of your

atom.workspaceView.command 'custom:semicolonize', ->
  editor = atom.workspace.getActiveEditor()


I must’ve done it wrong since I am getting an error when I invoke it via my keymap:

 'alt-enter': 'editor:insert-br'
 'alt-space': 'editor:insert-nbsp'
 'ctrl-u': 'sftp-deployment:uploadCurrentFile'
 'ctrl-alt-u': 'sftp-deployment:uploadOpenFiles'
 'shift-enter': 'custom:semicolonize'

(I put the block you posted into my


That’s what I get for not testing it :laughing:

If you change the first line of the function to:

editor = atom.workspace.getActiveEditor()

It should work. You may have to restart Atom first though.


Perfect! Many thanks.


Is anyone else running into issues with this using multiple panels?
Your solution adds the semicolon to the original panel, no matter what panel you’re currently editting


I’m getting this error:

Cannot read property ‘command’ of undefined

for the init script where I put this. Can anyone help?


The API has changed quite a bit since that snippet was posted. You should use the following now:

atom.commands.add 'atom-workspace', 'custom:semicolonize', ->
  editor = atom.workspace.getActiveTextEditor()


@michaelaye Try this:

atom.commands.add atom.views.getView(atom.workspace), 'custom:semicolonize', ->
  editor = atom.workspace.getActiveTextEditor()


Makes me think of a similar scenario for the autocomplete service:
If autocompleting a method name, it could/should add an opening and closing bracket immediately afterwards; and if the language of the file is one that requires semicolons, add that at the end as well.
After that it should return inside the brackets.


Doesn’t autocomplete already support snippets? If so then this would seem doable.


Ok, so I got the command implemented. Actually, I implemented the colonized version of it:

atom.commands.add 'atom-workspace', 'custom:colonize', ->
  editor = atom.workspace.getActiveTextEditor()

because I want this ability for Python. I got 2 probs with it.

  1. The keyboard command does not activate within a Python grammar, am I missing something? I got simply this in keymap.cson:

    ‘shift-enter’: ‘custom:colonize’

  2. If I activate the command via the command palette, it does not respect the current Python indent. How could I achieve that?

Thanks for helping an Atom noob. This editor is great fun!


Have you tried using the Keybinding Resolver (Cmd+. on OS X and Ctrl+. on other platforms)? It will show you what key Atom saw you press and the command that was triggered because of it.

I’m not sure what you mean by this. Can you give some repro steps?


Used the Keybinding Resolver. I used Shift-Enter as described above. It shows me that first (in green font) ‘editor:newline’ from atom-workspace atom-texteditor:not([mini]) has been used and in the 2nd line (in black font) my command is listed, with the 2nd column stating atom-text-editor. Do I have to control their order somehow?

With not respecting the current Python indent I simply mean that if my current line starts in column 5 and I execute my command via the command palette, the cursor ends up being in column 1 instead of column 5.


In essence, yes. Key bindings follow CSS specificity rules:

So what you have to do is make your key binding at least as specific as the built-in one. The easy way is to copy the selector from the winning one and use that for your key binding:

'atom-workspace atom-texteditor:not([mini])':
  'shift-enter': 'custom:colonize'

For this, you could extend the command to detect the indentation level of the current line and duplicate that when inserting the text.


Does not work, now only the previous winning one appears and mine is gone.


Oops … I copy-pasted your text for the selector without proofreading, it should look like this:

'atom-workspace atom-text-editor:not([mini])':
  'shift-enter': 'custom:colonize'


Sorry, my bad. Works now. For the indentation, all that was required was adding this to the end of the function:


and it seems to work now, cool!


But the enter/return key already knows how to do that, so wouldn’t it be better to execute that command instead of inserting a literal newline character?

In Python, if I’m not mistaken, then after a colon you get an additional indent.


and how do I press programmatically the Enter/Return key? :wink: