VSCodeVim / VSCodeVim/Vim

Implement motions: [m and ]m (go to method)

Open
#8,502 1 comment 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.2k
Forks
1.5k
Avg merge
3d 18h
Merged PRs (30d)
6

Description

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 ]M and [M using this plugin.
  • 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.
    • 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).

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:
2023-07-16 21 22 58

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Vim motion.txt documentation linked in the issue and review how the VSCodeVim extension currently handles motion key maps. Define behavior for ]m, [m, ]M, and [M across supported Java and other language files, including counts and method boundaries. Done means the mappings match Vim's documented navigation behavior and are covered by appropriate extension tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.