1

Suppose that I have a file that looks like this:

aaa
  bbb
   ccc

If I select lines 2 and 3 in visual mode and reindent with =, the result is everything in the same line:

aaa
bbb
ccc

Is there a way to ask vim to preserve the relative indentation inside the selection, so the end result looks like the following instead?

aaa
bbb
 ccc

Basically, I would like to automatically reindent the first line of the selection and then shift the remaining lines left or right by the same amount that the first line was shifted.

5
  • Start reading from :h 'equalprg' then revise your question by adding, at the very least, values of equalprg and filetype.
    – Matt
    Jun 21, 2020 at 3:36
  • If it helps, you can assume that this is a txt text file and that equalprg is unset (which is the default)
    – hugomg
    Jun 21, 2020 at 4:16
  • Just select indent with ^V and delete it; or setl sw=1 and shift with 2<<
    – Matt
    Jun 21, 2020 at 5:04
  • That does't automatically detect the indentation level of the frst line. I want the first line to end up the same place it would be if we reindented to with =
    – hugomg
    Jun 21, 2020 at 11:21
  • Then revenons à nos moutons: what is equalprg, filetype, indentexpr, cindent, etc.etc.
    – Matt
    Jun 21, 2020 at 11:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.