Alexey Gravanov

Fixing Home & End buttons in Sublime Text

Oct 27, 2015

Sublime Text is one of the best text editors I've ever seen. It is blazing fast, has tons of features like intellisense and highly customizable with hundreds of plug-ins developed by the great community.

After switching to Mac, I was confused by behavior of Home and End buttons in Sublime Text for MacOS. Instead of moving your cursor to the beginning and end of line, like in every other developer's editor I've ever used, they were moving you to the beginning and end of file, accordingly. Yes, I know, it is a MacOS default behavior and probably is more intuitive for people who not writing code than the one I was expecting. Apparently, I write a lot of code and thus missed possibilities of quickly jumping here and there in code and selecting lines of code.

So, to get desired behavior back, go to menu Sublime Text > Preferences > Key Bindings - User and add the following key bindings to the config file:

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

Now, Home will move the cursor to the beginning of the line, End - to the end of the line. Same for selecting text, Shift + Home will select text to the beginning of the line, End - to the end of the line.

Wait, what about going to the beginning and end of the file? We just replaced it with another behavior! Well, it's quite usual to have Cmd + Home and Cmd + End for that. Use the following key bindings to enable it:

{ "keys": ["super+home"], "command": "move_to", "args": { "to": "bof" } },
{ "keys": ["super+end"], "command": "move_to", "args": { "to": "eof" } },
{ "keys": ["super+shift+home"], "command": "move_to", "args": { "to": "bof", "extend": true } },
{ "keys": ["super+shift+end"], "command": "move_to", "args": { "to": "eof", "extend": true } },