Sublime Forum

Automatic jump to end of file on open for file type

#1

Whenever I open files with text or markdown extensions, I want to jump to the end of the file. I didn’t see a syntax-specific preferences to do this. Is it possible in preferences or some other way? I haven’t experimented with macros in Sublime: can these be invoked when a certain file type is opened?

0 Likes

#2

This would need to be done by a plugin.

0 Likes

#3
import sublime_plugin


class FileLoadedScrollToEnd(sublime_plugin.ViewEventListener):
    targeted_selectors = set(
        "text.html.markdown",
    )

    def on_load(self) -> None:
        if any(self.view.match_selector(0, selector) for selector in self.targeted_selectors):
            self.view.run_command("move_to", {"to": "eof"})
2 Likes

#4

For what it’s worth, a shorter way to jump the cursor to the bottom of the file is:

self.view.run_command('move_to', {'to': 'eof'})
2 Likes

#5

Thank you for the help-- that did the trick. Strangely, typewriter scroll page re-centering isn’t working even though “Text commands after which to center the view” in preference includes move_to. The behavior is that on opening, only the last line of text on the page appears, and that line is at the very top of the page. A manual carriage return then re-centers. So perhaps commands invoked through on_load don’t register as a move_to. If anyone knows why this might be, please let me know.

0 Likes