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.