I’m using sublime text 2 on windows. Are there keyboard shortcuts to go to the beginning and end of a line? If not, how I can I create them? And is there an official list of keyboard shortcuts anywhere? Can’t seem to find one.
Keyboard shortcut to go to beginning/end of line?
Well that works, thanks. But it seems a bit inconvenient to press… Is there a way to rebind it? I was thinking Ctrl+Alt left/right arrow.
Add the following entries to your user key bindings.
{ "keys": "ctrl+alt+left"], "command": "move_to", "args": {"to": "bol", "extend": false} },
{ "keys": "ctrl+alt+right"], "command": "move_to", "args": {"to": "eol", "extend": false} }
For future reference, you can rebind any keys you want in a similar fashion. Simply look up the command in the key binding file. Alternatively, if you know of a key combination that executes the command you want, you may enter “sublime.log_commands(True)” in the console. Then press the appropriate key binding. This will print out the command being executed to the console and the associated arguments.
JUST FYI for windows users - ctrl+super+left
and ctrl+super+right
is better choice.
I think better idea for WINDOWS users is alt+left / right cause default ctrl + left / right does the same as alt + left / right (go to end of word).
Ctrl + Left|Right moves by words, while Alt + Left|Right moves by sub-words.
Reference: Default (Windows).sublime-keymap
probably useful to mention what subwords are I’ve done a very quick test, so far, they seem to be _
characters, the upper case chars in camelCase etc.
I believe that the move
by:subwords
command uses any characters from the word_separators
setting as stop points.
( plus camelCase like you mentioned )
Default Values:
"word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}
~?",`
You can add this to use the Home/End keys on a regular keyboard on Mac:
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
Source: https://coderwall.com/p/upolqw/fix-sublime-text-home-and-end-key-usage-on-mac-osx
This works fine thanks! However eol
moves the caret to the first non-indentation character in the line, rather than to the beginning of the line. To move to the beginning/end of the line, I found ctrl+a
and ctrl+e
to work fine, respectively.
PS. There should be opening square brackets just before ctrl
on both lines of your shortcuts
This package contains a workaround to home not moving to the beginning of indentation line
- home move cursor to beginning of line (this one goes all the way to the beginning whereas the native one goes to the beginning of indentation)
- end move cursor to end of line
The native home does both. By pressing it several times “toggles” the caret position between the real beginning of the line and the beginning of the first nonewhitespace character.
The native end always moves the caret to the eol
even if it ends with whitespace.
I can’t find anything wrong with the native behavior.
So, my personal workaround is the following alteration to @skuroda’s answer :
{ "keys": ["ctrl+a"], "command": "move_to", "args": {"to": "bol", "extend": false} }
This is because I like the functionality of ctrl+a
ctrl+e
because I don’t have to move off the central keys, but don’t always want to go all the way to the beginning of the line with ctrl+a
and would usually prefer to be at the first non-whitespace character. This gives ctrl+a
the same functionality as cmd+left
on a Mac; i.e, toggles between beginning of line and first non-whitespace character. Also, you can do the following to remap ctrl+e
to have the same behavior as cmd+right
, though I don’t prefer it:
{ "keys": ["ctrl+e"], "command": "move_to", "args": {"to": "eol", "extend": false} }
Is there a way to turn this off without overwriting the keymap? I don’t find it in the prefs and having cmd-left go to the first non-whitespace is pesky for me, since I’ve got a few decades of muscle memory that expects it to go to the start of the line.
For now I’m using this (note the “hardbol”):
{ "keys": ["super+left"], "command": "move_to", "args": {"to": "hardbol"} }
Depends on what you mean by “overwriting” the keymap; what you’d do is exactly what you’re doing now, only specify home
as the key instead of that one. Then, when you press it your custom binding takes precedence and does what you want.