Search code examples
macossublimetext2sublimetextsublimetext3key-bindings

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


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?


Solution

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