Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to jump to next argument without going into nested function calls #493

Open
mnussbaum opened this issue Sep 21, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@mnussbaum
Copy link

I'm hoping to write a macro that involves jumping to a second argument of a function call and deleting it. The function arguments will sometimes include nested function calls, sometimes not, will sometimes be on multiple lines, and sometimes all on one line. I'm struggling to figure out how to use nvim-treesitter-textobjects to achieve the desired jumps.

My move configuration currently looks like this:

require'nvim-treesitter.configs'.setup {
  textobjects = {
     move = {
       enable = true,
       set_jumps = true,

       goto_previous_start = {
         ["[["] = "@parameter.inner",
       },
       goto_next_start = {
         ["]]"] = "@parameter.inner",
       },
     },
  },
}

And then for example, with a code snippet like this:

func foo(a, b int) int {
  return a * b
}

func bar(a, b int) int {
  return a + b
}

func main() {
  foo(
    bar(
      1, 
      2,
    ),
    3,
  )
}

When my cursor is on bar, and I hit ]], I'd like it to jump to 3, the next argument at the same level as the current node. However, it currently jumps to 1, the next argument at the lower level of the nested function call.

Any suggestions for how to achieve this desired jump? Thank you for your help!

@mnussbaum mnussbaum added the bug Something isn't working label Sep 21, 2023
@rockyzhang24
Copy link

On bar, hit % will jump to bar's closing parenthesis (this is the default behavior of matchit, see :h matchit for details), and then hit ]] will jump to 3. This workaround just one more key to press so I think it's acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants