Sublime Forum

Jump Along Indent


One thing I missed a lot coming from TextMate was the ability to jump up and down the page to lines at the same indent level:

I made a small plugin that reproduces this functionality, including extending your selection while jumping. You can find the source on github and install it using Package Control.

Feedback and suggestions are welcome!


Option-up/down Scope Navigation

Cool! This is very useful for prose writing, as it allows me to skip from paragraph to paragraph. (In prose writing a paragraph is a indistinguishable from a line of code, except that they occupy several “lines” due to soft wrapping, which your plugin disregards.)

Would it be possible to add a setting for taking whitespace into account along with indenting? That is, to provide an option to stop the cursor stop on the first “line” (with soft-wrap) after and before a line of whitespace. (In the same way that Ctrl+Left/Right moves from word to word, but also allows you to move to the beginning and end of the current word).

Does this make sense?


Edit: Is that font Anonymous Pro?



I’m glad you like it! I really like your suggestion, and I’ve implemented it for several lines at the same indent level. Unfortunately, I couldn’t find a good way to take soft-wrapped lines into account. I could probably do it if you use a monospace font by checking the width of the window and dividing by the width of the characters, but that’s pretty hacky. Does anyone know of a better way of finding the beginnings of soft-wrapped lines?

The font is Source Code Pro Light by Adobe.



I thought I was confusing . . . I actually like that your plugin disregards soft-wrapped lines. The addition I was asking for was some consideration for whitespace. The closest thing I can come up with is to look at how Ctrl+Left/Right works. When you are within a word, moving to the right takes you to the end of the word before (on the next press) you are taken to the end of the next word and so on.

Let me try and explain at the level of the “paragraph” (i.e., loads of soft-wrapped text):

Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Suspendisse malesuada semper
lectus, quis adipiscing metus aliquam vitae.

Morbi commodo, scelerisque laoreet,
magna elit | vestibulum ligula,
vitae eleifend risus erat vel lorem.

Dignissim ullamcorper nulla pharetra non.
Mauris arcu vel eros hendrerit vitae semper
tortor sodales. Vestibulum vel tincidunt metus.

If the cursor is between elit and vestibulum, I would like Alt+Up to move me to commodo and then to ipsum. If I then press Alt+Down, it would move me to quis and then eleifend (approximately).

Does this make sense? (And is it possible?)




So it actually does work that way now with separate lines. The problem is that it sees the paragraphs as one long line, so there’s no way to jump to the last “line” of the paragraph. If there’s a good way of identifying soft-wrapped lines, then I could definitely implement it. In the meantime, I’ll try implementing it by dividing the window width by the character width.



Thanks for sharing.



Thanks for developing this plugin!

It was almost what I wanted, so I had a go and made two commands that do something similar. They are not as smart as Jump Along Indent. They only “jump to top/bottom” of the current level of indentation. The indent region is determined by using the build-in command “expand_selection to indentation”.

Here is the plugin code:

class JumpToIndentTopCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("expand_selection",{"to": "indentation"})
        pos = self.view.sel()[0].a

class JumpToIndentBottomCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("expand_selection",{"to": "indentation"})
        pos = self.view.line(self.view.sel()[0].b-1).a

Like Jump Along Indent, I then bind these two commands to alt+up and alt+down .

I actually use a slightly different version of this to move one line further up. So it jumps “up” a level, which helps in language like Python: with a couple of jumps, you can easily land on the current code scope’s def or class. This is close to the operation achieved by using goto symbol (ctrl+r) then jump to the current def or next def.

This is probably not perfect, I haven’t used it long enough to know all the quirks in various situation. Who knows, maybe one day I will switch back and use Jump Along Indent. But maybe someone will find this useful. Or maybe someone can point out how I can improve this. :smile: