philosopher
philosopher

Reputation: 81

Atom - Adding a keybind shortcut to insert code snippet

I'm trying to create a keybind in the Atom text editor that will insert the code:

<cfdump var="##">

and

<cfabort>

using ctrl+shift+d and ctrl+shift+a respectively, just as it is in Eclipse. The previous posts don't touch on this issue.

So far, I've tried editing the keymap.cson file with

'atom-text-editor':
  'ctrl-shift-d': 'custom:insert-dump'

'atom-text-editor':
  'ctrl-shift-a': 'custom:insert-abort'

and adding the below to init.coffee:

atom.commands.add 'atom-text-editor',
  'custom:insert-dump':   ->
    atom.workspace.getActiveTextEditor()?.insertText('<cfdump var=\"\#\#\">')

atom.commands.add 'atom-text-editor',
  'custom:insert-abort':   ->
    atom.workspace.getActiveTextEditor()?.insertText('<cfabort>')

I've managed to get the < cfabort > to work, but the cfdump just produces a newline. I'm sure I'm making some silly mistake. Any suggestions?

Thank you.

Upvotes: 4

Views: 1229

Answers (2)

easy web dev
easy web dev

Reputation: 1

You can fix it by changing the keymap.cson to:

'atom-text-editor':
  'ctrl-shift-d': 'custom:insert-dump'
  'ctrl-shift-a': 'custom:insert-abort'

and the init.coffee to:

atom.commands.add 'atom-text-editor',
  'custom:insert-dump':   ->
    atom.workspace.getActiveTextEditor()?.insertText('<cfdump var=\"\#\#\">')
  'custom:insert-abort':   ->
    atom.workspace.getActiveTextEditor()?.insertText('<cfabort>')

Upvotes: 0

user1319153
user1319153

Reputation: 31

In keymap.cson, I added:

 'atom-text-editor':
   'alt-q': 'custom:tom'

In init.coffee, I added:

atom.commands.add 'atom-text-editor', 'custom:tom', ->
  editor = atom.workspace.getActiveTextEditor()
  tomstring  = editor.getSelectedText()
  editor.insertNewlineBelow()
  editor.insertText('<cfdump var="#'+tomstring+'#" label="'+tomstring+'"><cfabort>')
  editor.save()

To use in the editor hightlight what you want to dump and do alt-q.

Upvotes: 3

Related Questions