5

For indenting there's no problem. I enter the visual-block mode, select the block, enter insert mode, press ctrl-t (or just press tab), exit the visual-block mode, and the whole block is indented.

So, for the following code:

def my_function():
print('entering my_function')
print('leaving my_function')

Results in:

def my_function():
    print('entering my_function')
    print('leaving my_function')

Taking this last piece of code, if I follow the same steps as described in the first paragraph, but pressing ctrl-d instead of ctrl-t, the result is the following:

def my_function():
    print('entering my_function')
print('leaving my_function')

Even if select both lines in the visual-block mode, only the one on which I apply the unindent command gets affected.

1
  • It was gracious of you to accept my original answer when I'd completely failed to read your question properly. Not sure why outdent doesn't work in insert-via-visual-block mode when indent does. Might be worth raising it as an issue on the Vim repository or in the vimdev mailing list if you're still curious.
    – Rich
    Commented Feb 17, 2023 at 13:28

2 Answers 2

11

You don't need to enter insert mode via visual-block mode to indent/outdent multiple lines: you can do it directly from visual mode by pressing > for indent and < for outdent. (See :help v_< and :help v_>)

To indent multiple levels, you can either repeat the operation by pressing . or pass a count to the </> command.

0

This is quite easy also: let's suppose we want to remove the extra tab space in our bock code of the lines 2 and 3

1 def my_function():
2         print('entering my_function')
3         print('leaving my_function')

Steep one: enter in visual mode (Ctrl+V) and use arrows keys for select a four spaces width area like this:

1 def my_function():
2     ████print('entering my_function')
3     ████print('leaving my_function')

Steep two: just press d:

1 def my_function():
2     print('entering my_function')
3     print('leaving my_function')

-Tadaa!

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.