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.

2 Likes

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

0 Likes

#4

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

1 Like

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

3 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

4 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