3

I often edit Python code that needs to be re-indented other otherwise manipulated through visual selection.

Is there any way to visually select all lines of the same indentation in Vim?

I know I could do V+<n>j to select the current line and the <n> lines below it. However, I don't want to count the lines beforehand.

Furthermore, I have experimented with V}, which seem to work, except it doesn't select all lines of there is space between them, and it doesn't select in both directions (up and down).

5

I think your best bet is to use a plugin like vim-indent-object it defines some new text objects to handle indentation levels:

enter image description here

Other alternatives are either:

  • Creating your own text objects manually as described here which is more or less reimplementing the plugin I mentioned before
  • Using a library like vim-textobj-user which helps you creating new text objects more easily, but which might be a bit overkill for what you want to do.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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