5

I've been authoring a lot of F# in Vim lately. Like Python it is pretty strictly indentation-based. However, unlike Python mode for Vim, it does not appear that the standard F# Vim plugin supports any kinds of motions. I would like the ability to rapidly navigate over modules and functions, in the spirit of what is done with motions for classes and functions in Python mode:

[M      Jump to previous class or method (normal, visual, operator modes)
]M      Jump to next class or method (normal, visual, operator modes)
aC      Select a class. Ex: vaC, daC, yaC, caC (normal, operator modes)
iC      Select inner class. Ex: viC, diC, yiC, ciC (normal, operator modes)
aM      Select a function or method. Ex: vaM, daM, yaM, caM (normal, operator modes)
iM      Select inner function or method. Ex: viM, diM, yiM, ciM (normal, operator modes)

So specifically, given some code like this:

module Foobar =
    let private foo'() =
        bar'()
        |> baz'()
        |> qux'()

    let foo() =
        bar()
        |> baz()
        |> qux()

I would like to be able to quick jump to the beginning and end of functions and modules.

I can write some code to do this based on Python mode, but before jumping to that I was wondering, since Vim comes with so many motions built in, Is there a way to say, "move to the first place where there is a nonblank line that is set back n indentation levels from current line"?

I have not been able to find anything, maybe because Vim was built originally more for C-style code, but I wanted to know if there was any existing functionality (or existing plugin for that matter) that handled this case, because if so that would probably take care of 95% of what I need without having to implement the motions for F#-specific semantics.

2

1 Answer 1

4

Plugin indentwise by jeetsukumaran

Movements by Relative Indent-Depth

  • [- : Move to previous line of lesser indent than the current line.
  • [+ : Move to previous line of greater indent than the current line.
  • [= : Move to previous line of same indent as the current line that is separated from the current line by lines of different indents.
  • ]- : Move to next line of lesser indent than the current line.
  • ]+ : Move to next line of greater indent than the current line.
  • ]= : Move to next line of same indent as the current line that is separated from the current line by lines of different indents.

Movements by Absolute Indent-Levels

  • {count}[_ : Move to previous line with indent-level of {count}.
  • {count}]_ : Move to next line with indent-level of {count}.

Movements by Indent-Block Scope

  • [% : Move to beginning of indent-block scope (i.e., move to the line just after the previous line of lesser indent); repeat for {count} outer scopes.
  • ]% : Move to end of indent-block scope (i.e., move to the line just before the next line of lesser indent); repeat for {count} outer scopes.

    If you use matchit's (matchup) [% and ]%, you have to pick different ones (#issue 6).

Remarks

Futher related plugins are

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.