Implement motions: [m and ]m (go to method)
Is your feature request related to a problem? Please describe.
When working with Java files where everything is inside a class, it's very useful to navigate to the start or end of methods. Currently, there is no easy way to do this in VSCodeVim since the Vim method navigation motions (mainly [m and ]m) are missing. So I'm left with relative line jumping or guessing [{ to achieve the same result that a single [m/]m would do.
Describe the solution you'd like
In Vim, method navigation is done with the key maps ]m (next method start) and [m (previous method start). Similarly, ]M (next method end) and [M (previous method end) also exist to go to the end of methods.
Please implement these key maps (]m/[m/]M/[M), following the behavior of Vim (https://vimhelp.org/motion.txt.html#%5Dm). In my opinion, the most useful mappings are ]m and [m, so I think that at least those should be implemented (hence the title of the issue).
Describe alternatives you've considered
- Use this plugin to navigate only method members: https://github.com/mishkinf/vscode-goto-next-previous-member
- Problems:
- The cursor does not go to the starting brace of the methods, it goes to the method name (not Vim's behavior).
- Not sure if possible to implement
]Mand[Musing this plugin.
- Problems:
- Don't try to use
]m/[m/etc. altogether and instead rely on other Vim motions.- Relative line jump
- Problems:
- The command is not always the same (the count may be different).
- Not viable when the method is too long that the method signature is not visible in the editor.
- Problems:
- Motions
[{/]}- Problems:
- The command may have to be typed more than once (since a single execution may not be enough, like when the cursor is inside an if statement).
- Problems:
- Relative line jump
Additional context Vim help on these method motions: https://vimhelp.org/motion.txt.html#%5Dm
Demo of the desired behavior. Going up the file with [m and down with ]M:
Though not exactly but another alternative you can consider using is the VS Code built in commands
- Go to Previous Folding Range (
editor.gotoNextFold) - Go to Next Folding Range (
editor.gotoPreviousFold)
I have mapped these to ]m and [m respectively.
This only work if you are outside the method or inside method with no additional indent blocks. Where there are more foldable blocks will not work.
Ref: https://stackoverflow.com/questions/39448562/vs-code-go-to-next-previous-member