Sublime Forum

Keyboard shortcut to go to beginning/end of line?

#1

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.

1 Like

Shortcuts to jump to sentence/paragraph start/end
#2

Home and End?

:smile:

2 Likes

#3

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.

1 Like

#4

on the mac, it’s command-left and command-right

0 Likes

#5

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.

4 Likes

#6

Great, worked perfectly, thanks a lot.

0 Likes

#7

JUST FYI for windows users - ctrl+super+left and ctrl+super+right is better choice.

0 Likes

#8

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).

0 Likes

#9

 
Ctrl + Left|Right moves by words, while Alt + Left|Right moves by sub-words.

 
Reference: Default (Windows).sublime-keymap

1 Like

#10

probably useful to mention what subwords are :wink: I’ve done a very quick test, so far, they seem to be _ characters, the upper case chars in camelCase etc.

2 Likes

#11

 
I believe that the move  by:subwords  command uses any characters from the word_separators setting as stop points.
( plus camelCase like you mentioned ) :+1:

 
Default Values:
"word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?",`

2 Likes

#12

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

2 Likes

#13

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 :slightly_smiling:

1 Like

#14

Shh, let’s not talk about my typos :slightly_smiling:

1 Like

#15

you can use combination button (ctrl+fn+home/end)

0 Likes

#16

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
0 Likes

#17

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.

2 Likes

#18

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} }
0 Likes

#19

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"} }

0 Likes

#20

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.

0 Likes