Toggle Soft Wrap : Key Binding


#1

Is there a way to bind a set of keys to “Toggle Soft Wrap” ?


#2

I wanted to do precisely this, but am falling at the first hurdle. I tried adding these lines to my keymap.cson file:

'.editor':
  'alt-cmd-\': 'editor:softWrap'

but this seems to have no effect (after restarting app, too). What is the correct way of adding this toggle to the keybinding? (I’m surprised it isn’t already assigned “out of the box”, actually!)

Thanks!


#3

There are a few issues with your example:

  1. The command is editor:toggle-soft-wrap
  2. The syntax you have for the keystroke is incorrect, it should be 'alt-cmd-\\'. The single backslash escapes the single quote so the string doesn’t end until just before the e in editor.
  3. Cmd+Alt+\ conflicted with one of the default keyboard shortcuts in my installation of 1Password.

Even when I disabled that shortcut, Cmd+Alt+\ was not recognized properly … but when I changed the keymap to use Cmd+Alt+Shift+Z (a key combination that I use specifically for testing key mappings because I know I’m not going to use it for anything else), everything worked fine. I’ve filed a bug about the Cmd+Alt+\ thing … because the behavior just seems weird when I look at it using the Keybinding Resolver.


Turn on Line Wrap
#4

Thanks so much for spelling that out. Maybe I should have guessed about double-backslash; OTOH, it would be welcome to have that noted in the documentation (and if it’s there, I missed it: I did read it! really!)

Interestingly enough cmd-alt-\\ works well for me (Ubuntu 14.04, fwiw). It’s the same combination as the TextAdept toggle, and I prefer not to proliferate these if I don’t have to.

Where would one look to know that toggle-soft-wrap is the correct form for this feature? I didn’t spot that either. (So not doing very well, then! =/)

Meanwhile, it’s good to have this example working. Thanks again!


#5

Actually, what caught that for me was the CSON syntax highlighting :laughing:

I used Cmd+Shift+P to bring up the Command Palette and then typed soft to search for soft wrap, found the command:

Then I just reversed the standard string conversion: Editor: Toggle Soft Wrapeditor:toggle-soft-wrap


#6

Awesome, thank you for posting this!

Took me way too long trying to figure out the necessary keymap command for a quick toggle for soft wrap. Is this helpful nugget officially documented somewhere? I looked to no avail…

I tried guessing (unsuccessfully) based on the corresponding API method, but your instructions were dead on!


#7

The new documentation has an in-depth section on key bindings: https://atom.io/docs/latest/behind-atom-keymaps-in-depth.

In particular, the last paragraph of the Commands section states:


#8

I want the soft wrap to be on, by default. Is that possible?


#9
  1. Launch Atom
  2. Open the Settings View using Cmd+, on OS X or Ctrl+, on other platforms
  3. Scroll down to the box marked “Soft Wrap”
  4. Put a check in it

#10

Ah, there it is:) Your the man leedohm, thank you.