Sublime Forum

Command to move by several lines

#1

Hi there, I’m a recent fan of ST3.
My suggestion is to add an option to “move” command, so that it accepts in arguments not only “by” (“characters”, “lines”, “pages”,…), but also how much “by” (e.g., by 10 lines). The point is that I want to navigate conveniently, and one line is too small, one page is too big, so I want a shortcut to move the caret, say, by 10 lines. Maybe I’ve missed something, and this functionality is possible in the current version of ST?

0 Likes

#2

Ok, so there was a similar question back 5 years ago. Pity that this rather useful option has not been introduced during 5 years.

0 Likes

#3

If I had to guess I would say that the reason the core doesn’t do this on its own is because you can add your own movement command that takes an extra argument if you want it so it’s not really needed.

For example, this creates a move_amount command that takes an extra argument named amount that describes how many times the motion should be taken. With this in place you can duplicate an existing key binding for movement with an appropriately added new modifier and just change the command from move to move_amount, add in an amount argument and away you go.

import sublime
import sublime_plugin

class MoveAmountCommand(sublime_plugin.TextCommand):
    def run(self, edit, amount=1, **kwargs):
        for _ in range(amount):
            self.view.run_command("move", args=kwargs)

3 Likes

Move up or down by N lines
Move cursor up or down a few lines at a time from the keyboard
#4

Wow, it works! Many thanks! There is nothing impossible with ST3 :slight_smile:

1 Like