Sublime Forum

Change "alt+shift+w" shortcut

#1

I am using sublime 2, and i put a new line
{ “keys”: [“alt+shift+w”], “command”: “wrap_lines” }
in
~/.config/sublime-text-2/Packages/User/Default (Linux).sublime-keymap

but the lines still don’t wrap. Please help

0 Likes

#2

Did you verify that you put a comma after the line before it (if you added it at the end of the file), or one after it (if you added it before something else)?

In other words, have you verified that your sublime-keymap file is still valid JSON?

0 Likes

#3

Yes, it looks like that:

[
{ “keys”: [“alt+shift+w”], “command”: “wrap_lines” },
{ “keys”: [“ctrl+shift+c”], “command”: “copy_path” }
]

0 Likes

#4

Odd. That should work. On mine, I had to restart Sublime Text before it picked up the change. If you’ve done that, the only thing I can suggest is, try removing the copy_path line? I mention this only because I couldn’t find any copy_path command in my existing key-bindings, so maybe your syntax for that is wrong, and if so, maybe it’s messing up the other part.

0 Likes

#5

NOTE: Everything below applies to both Sublime Text 2 and 3 unless otherwise indicated. I verified using the latest available version of both (Sublime Text 2 build 2221 and Sublime Text 3 build 3126).

I switched the contents of my Default (Linux).sublime-keymap file to exactly the contents that you referenced above, and it works just fine for me; I didn’t have to restart Sublime to get it to notice the change.

Although copy_path doesn’t appear in the default key bindings, it’s an existing command defined in Default\copy_path.py and available as Copy File Path from the context menu and (for Sublime Text 3) as File: Copy Path from the command palette, plus other places most likely (such as the sidebar, but I did not verify that this is the case for default sublime).

For what it’s worth, Sublime doesn’t seem to mind if you bind a key to a command that does not exist; that key just does nothing. If you run through the steps outlined below you can verify that even if you bind a key to a command that doesn’t exist, it still gets logged but no error messages are generated. This can be a potential cause for error; if you misspell the command name, it might look right, but it will still do nothing.

I would suggest trying the following steps to narrow in on what’s going on:

  1. Select View > Show Console from the menu (or press Ctrl+`)
  2. In the console, enter the command sublime.log_commands (True) and hit enter; you should see the console respond with:

>>> sublime.log_commands (True)

  1. Return focus to a test file and press Alt+Shift+W

Regardless of what happens in the actual file, if you see the console say:

command: wrap_lines

Then your key binding worked and the problem is that Sublime doesn’t think it needs to wrap anything, which is something else that we can look into (text doesn’t need to be wrapped, the margin is wrong, etc). If it doesn’t say that, or it mentions another command when you press the key (for example insert_snippet, which is what that key seems to be bound to by default), then your key binding is not being recognized for some reason.

Once you’re done testing, you should either restart Sublime or use sublime.log_commands (False) in the console to turn off command logging.

0 Likes

#6

I did get

command: wrap_lines

I also tried replacing wrap_lines with word_wrap. The same problem, But console is showing

command: word_wrap

But, if I do “view -> word wrap”, it works what i want with shortcut, and console is showing

command: toggle_setting {“setting”: “word_wrap”}

0 Likes

#7

Aha! If you want your key combination to toggle the state of the word wrap setting, your file needs to look like this (also includes your binding for copying the file path):

[
{ "keys": ["alt+shift+w"], "command": "toggle_setting", "args": {"setting": "word_wrap"}},
{ "keys": ["ctrl+shift+c"], "command": "copy_path" }
]

The wrap_lines command wraps lines at the first ruler’s column (or at the column you specify as an argument, if you give one) which physically modifies the file instead of switching the state of word wrap on and off.

0 Likes

#8

Seems that I misunderstood the command. Sorry for that.
That really works. Thank you.

1 Like