Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have a custom keystroke insert a Unicode char in Atom

Tags:

atom-editor

Is there a way to get the Atom editor to insert a custom Unicode character when you press a shortcut key? I'm trying to make Cmd-\ insert a lambda (λ).

like image 241
Sam Washburn Avatar asked May 20 '15 18:05

Sam Washburn


People also ask

How do you show special characters in an atom?

Displaying Invisible Characters in Atom To display spaces, tabs and linebreaks in Atom, you'll need to go to “Settings” -> “Editor” and then scroll down until you find the “Show Invisibles” option.

What is the shortcut for run in atom?

In the "Script" package, The keyboard shortcut to "Run Script" is shift+ctrl+b .


1 Answers

You can create a custom command and then map that command to the desired key. To add the custom command you can add this to your init.coffee:

atom.commands.add 'atom-text-editor',
  'custom:insert-lambda': (event) ->
    editor = @getModel()
    editor.insertText('λ')

Then you can add the key mapping in your keymap.cson:

'atom-text-editor':
  'cmd-\\': 'custom:insert-lambda'

After restarting or reloading the window to load the new init.coffee, things should work for you.

like image 108
Lee Avatar answered Sep 22 '22 16:09

Lee