0

I am following along in the book Vi IMproved by Steve Oualline.

In Chapter 7, "Commands for Programmers", there is a discussion about indentation and the = command.

Here is what I wrote in my file

{
if True
return 1;
statement;
statement;
}

Then, as instructed by the book, I positioned my cursor on the first "{" and pressed "=%". The result was

{
        if True
        return 1;
        statement;
        statement;
        }

The book shows only the content within the braces being indented.

Why is the closing brace being indented?

2
  • The automatic indentation of the file generated by the = command (e.g. =% or =G) depend on your file type and your file type implementation. Your problem is probably laying there. Could you share your file type with us (:set filetype)? Jan 10 at 10:06
  • The full output of $ vim --version might be relevant, too. Both the example from the book and the example from OP work as expected, here.
    – romainl
    Jan 10 at 11:35

1 Answer 1

1

The automatic indentation of the file generated by the = command (e.g. =% or =G) depend on your file type and your file type implementation.

I can reproduce your problem when the filetype of the text (:set filetype?).

You have the odd behavior because the code block are not grouped with curly braces ({ }) in Python.

If you select a file type that is curly base compatible you will not have that effect.

:set filetype=c
2
  • @evianpring of this solution solves your problem may ne could you validate it using the green v button next to the arrow voting button. Approving solution makes them rest ;-) Jan 13 at 6:12
  • 1
    Indeed the issue happened in a python file.
    – evianpring
    Jan 14 at 6:26

Your Answer

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

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