I occasionally use remote desktop to connect from a Mac machine to a Windows development machine, which means that I need to remap the default keybindings for start/end of buffer because the “Home”/“End” keys aren’t available. As an alternative, would it be possible to support -1
as a valid input for “Goto Line” that aliases to end of file?
Support jumping to end of file with -1 line number
On a Mac keyboard that doesn’t have Home and End keys (which I assume is most but my experience is limited), Fn+Left is the Home key and Fn+Right is the End key.
As such, the key strokes you want out of the box to be able to use Sublime in a remote desktop session originating from a Mac are Fn+Ctrl+Left and Fn+Ctrl+Right to jump to the beginning or end of the file respectively.
Note also that Sublime sees e.g. Fn+Left as Home natively, so any other key binding that uses these keys will work with a similar replacement, and you would use home
or end
in your key binding if you want to create your own.
Failing that, if you bind prompt_goto_line
to a key it will ask you for a line number (near the status area) and then use the goto_line
command to jump there. So if you changed the binding for Ctrl+g to use that command instead, you sort of get what you want, and you would have to use ⌘+p followed by entering : to get at the default functionality.
Note that goto_line
has what I would call a bug in that it converts from 1 based line numbers to 0 based line numbers before it checks if it’s a negative line, and so the line -1
means the second to last line in the file, and -0
takes you to the last line.
Of course if you’re binding a key for the purposes of jumping to the last line of the file, the move_to
command is much more intuitive for that, so this is mostly of academic interest I would expect.
Thanks for the information, Fn+Ctrl+Left/Right does work. Does goto_line support negative line numbers? Both Ctrl+G or Cmd/Win+P+: don’t seem to do anything with any negative inputs for me, including -0 and -1.
The goto_line
(and prompt_goto_line
, which just asks you for a line number and then runs goto_line
for you) both support negative line indexes, yes.
This is different from what you see if you press ⌘+p,: (or just Ctrl+G, which is a shortcut that does both for you at once).
When you press either of those keys you’re seeing the Goto Anything
panel, where text prefixed by a :
is a line number. That panel doesn’t support negative line numbers for this command.