Sublime Text: How to set up begining of line/end of line shortcuts to match the shell?
Asked Answered
L

5

9

I've been using Sublime Text for a little while now (on MacBook Pro), and want to make it keystroke compatible with the shell.

In the shell, to jump to the beginning/end of line I press fn+Left/fn+Right.

In Sublime Text, I understand how to set up key bindings for fn+Left/fn+Right, but I see no key name for the fn key (not the f1, f2, etc. function keys, I am referring to the key marked "fn").

How can I make this work in Sublime Text?

Lucubration answered 6/11, 2014 at 9:1 Comment(0)
L
25

I guess I was making it too hard on myself.

  1. the fn button does not have a key name in Sublime Text.
  2. fn+Left/fn+Right is read as Home/End. Simply mapping home and end did the job.

Specifically:

Sublime Text | Preferences | Key Bindings - User
  • Add the following between the [ ]:

      { "keys": ["home"], "command": "move_to", "args": { "to": "hardbol" } },
      { "keys": ["end"], "command": "move_to", "args": { "to": "hardeol" } }
    

I discovered this by opening up the SublimeText console:

ctrl+`
sublime.log_input(True)

Now, typing any keys reveal their Sublime Text key names. fn did not elicit a response, but fn+Left/fn+Right yielded Home/End.

sublime.log_input(False)

Hope that helps.

Lucubration answered 6/11, 2014 at 9:1 Comment(0)
H
3

Open menu Sublime Text > Preferences > Key Bindings

Add the following to the array (between square brackets []):

{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
{ "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} },
{ "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true } }

You can now use the following combinations:

  • Go to beginning of line: Home
  • Go to end of line: End
  • Select from cursor position to beginning of line: +Home
  • Select from the cursor position to end of line: +End
Haig answered 18/8, 2022 at 8:4 Comment(0)
G
2

For me(on MBP):

cmd and left worked as Home

cmd and Right worked as End

Without changing any configuration in Preferences.

Guipure answered 19/1, 2017 at 3:56 Comment(0)
R
0

For adding the keybindings to ST4 on Macbook Pro (to match the windows ones with home and end), this worked

[
    { "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },   
    { "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
    { "keys": ["ctrl+home"], "command": "move_to", "args": {"to": "bof"} },   
    { "keys": ["ctrl+end"], "command": "move_to", "args": {"to": "eof"} },
    { "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} },
    { "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true } },
    { "keys": ["ctrl+shift+end"], "command": "move_to", "args": {"to": "eof", "extend": true} },
    { "keys": ["ctrl+shift+home"], "command": "move_to", "args": {"to": "bof", "extend": true } },
]
Robbi answered 6/11, 2022 at 12:20 Comment(0)
M
0

Here is a solution that is agnostic to Sublime and will also work with other programs (including Chrome etc)

mkdir -p ~/Library/KeyBindings/ && touch ~/Library/KeyBindings/DefaultKeyBinding.dict

Open ~/Library/KeyBindings/DefaultKeyBinding.dict and paste

{
    "\UF729"  = moveToBeginningOfLine:; // home
    "\UF72B"  = moveToEndOfLine:; // end
    "$\UF729" = moveToBeginningOfLineAndModifySelection:; // shift-home
    "$\UF72B" = moveToEndOfLineAndModifySelection:; // shift-end
}

You will have to quit and re-open Sublime Text (or any application) for this to take effect.

Source: https://apple.stackexchange.com/a/16137/234304

Metzgar answered 20/4, 2023 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.