Sublime Text 2: How to Page Up/Down without moving the cursor
Just using Fn+up
to pageup and Fn+down
to pagedown.
To do this requires a text plugin. Thanks to user bizoo on the ST Forums, you don't have to write this yourself:
http://www.sublimetext.com/forum/viewtopic.php?f=3&t=12793
This works exactly as I'd expect.
Sublime Text 3 Update: You can follow the instructions below, with the minor change that the file should end with .py
(e.g. scroll_lines_fixed.py
) and should be loose in the ~/Library/Application Support/Sublime Text 3/Packages/User/
folder.
Sublime Text 2 Update: This isn't clear, and also uses a bare URL which could conceivably die in the future. So here's a more complete explanation of what you need to do.
Add these four lines to Sublime Text 2 > Preferences > Key Bindings - User, inside any square brackets that are already in the file:
[ { "keys": ["ctrl+up"], "command": "scroll_lines_fixed", "args": {"amount": 1.0 } }, { "keys": ["ctrl+down"], "command": "scroll_lines_fixed", "args": {"amount": -1.0 } }, { "keys": ["pageup"], "command": "scroll_lines_fixed", "args" : {"by": "pages", "amount": 1.0 } }, { "keys": ["pagedown"], "command": "scroll_lines_fixed", "args" : {"by": "pages", "amount": -1.0 } } ]
- Within Sublime Text, choose the Tools > New Plugin… option from the menu bar.
Replace the contents of the new file with this:
import sublime, sublime_plugin class ScrollLinesFixedCommand(sublime_plugin.TextCommand): """Must work exactly as builtin scroll_lines command, but without moving the cursor when it goes out of the visible area.""" def run(self, edit, amount, by="lines"): # only needed if one empty selection if by != "lines" or (len(self.view.sel()) == 1 and self.view.sel()[0].empty()): maxy = self.view.layout_extent()[1] - self.view.line_height() curx, cury = self.view.viewport_position() if by == "pages": delta = self.view.viewport_extent()[1] else: delta = self.view.line_height() nexty = min(max(cury - delta * amount, 0), maxy) self.view.set_viewport_position((curx, nexty)) else: self.view.run_command("scroll_lines", {"amount": amount})
- Save the file to ~/Library/Application Support/Sublime Text 2/Packages/ScrollLinesFixed/. You will need to create the ScrollLinesFixed folder.
- There's no step 5.
Just my 2¢, but I have mine setup to scroll up or down with the following:
{ "keys": ["super+up"], "command": "scroll_lines", "args": {"amount": 1.0} },
{ "keys": ["super+down"], "command": "scroll_lines", "args": {"amount": -1.0} }
I use a Mac, so the "super" key is the command key, which is the first key to the left (or right) of the space bar. Not sure what the equivalent would be on Windoze; perhaps it would be the "Start" key or something. Anyway, works like a charm.