1

I use VsCode with the Vim plugin. In other languages using Vim to jump to brackets is good enough, but python if statements don't have brackets.

I have found no Vim plugin or macro for this, is it impossible?

There is this Vim plugin (and its even available in VsCode), but it does not support Python (per the maintainer in a github issue):

In raw vimscript (which the VsCode Vim plugin has some support for) I would need to jump to the next word matching else:, but only if its on the same level of indentation as the if I'm currently on.

I'm having trouble finding vimscript examples of moving the cursor to a location matching the same indent.

I just want to add I don't always have the luxury of formatting the code, I'm often reading others code. So I can't just always put a blank line between if and else and jump to next blank line or something like that.

3
  • It is not clear to me if you are searching a solution within VsCode or within Vim. Could you clarify? Jul 19, 2023 at 16:45
  • Does matchit not work? :help matchit perhaps :let b:match_words = '\<if\>:\<elif\>:\<else\>' in ~/.vim/after/ftplugin/python.vim?
    – D. Ben Knoble
    Jul 20, 2023 at 16:38
  • Also, the VSCode-specific parts are off-topic; only the Vim-behavior of the plugin is on-topic. I've edited to focus on those.
    – D. Ben Knoble
    Jul 20, 2023 at 16:39

1 Answer 1

1

You could be interested to the vim-indentwise plugin.

It allows you to navigate through the code by level of indentation:

  • [- one level down (e.g. from body of if to the if condition, from def to class)
  • [= same level up (e.g. from else to if)
  • ]= same level down (e.g. from if to else)
2

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.