How to create Key Binding for inserting text in editor


For example:

ctrl+f+u should insert string "function " (with space at the end)
ctrl+s should insert string “ś” (polish letter)

I would ask for detailed step-by-step explanation.


Want to take a stab at this @olmokramer?


I do not understand.


I’m asking another person who frequents the forum named @olmokramer, who specializes in modifications, to answer your question.


That would be very nice.


Follow these instructions after changing them to suit your needs:

  1. Add this to your

    atom.commands.add 'atom-text-editor',
      'custom:insert-foo': ->
  2. Add this to your keymap.cson

      'ctrl-shift-alt-z': 'custom:insert-foo'
  3. Restart Atom (to load the again)

The text above has the following replaceable parts:

  • custom:insert-foo is the command name, it can be changed to any string you want, though convention is package name and command text separated by a colon
  • foo (on the third line of step 1) is the text that is inserted
  • ctrl-shift-alt-z is the key combination to execute the command. It can be replaced with whatever key combination you want.

Also keep in mind that the keymap.cson (like other CSON files) follows certain rules that mean duplicate keys don’t work.


Yes @leedohm I would do exactly that :slight_smile:


Thanks, it worked.


Doesn’t work for me :frowning: It just inserts my text in sime random place when I start Atom.
I added

  'ctrl-shift-j': 'custom:insert-on-tap'


atom.commands.add 'atom-text-editor',
  'custom:insert-on-tap': ->
  atom.workspace.getActiveTextEditor()?.insertText(" = function(el) {el.addEventListener('transitionend', function(e) {});}")


In CoffeeScript, leading whitespace is significant. The third line in your second code block should be indented 2 more spaces.


Thanks, now it works!