1

I'm editing my ~/.vimrc this weekend, and I've run into a use case that seems to beg that I strip off indentation in an if-block.

Broken use-case in my ~/.vimrc (with if-block indentation):

if has('python3')
  python3 << EOF
# Insert python here
# more python
# and more python
  EOF
endif

Working use-case in my ~/.vimrc (without if-block indentation):

if has('python3')
python3 << EOF
# Insert python here...
# more python
# and more python
EOF
endif

As far as I can tell, the "Working use-case" (without indentation) is fine and vim seems to have no problems.

If I use the "Broken use-case" (with indentation in the vimscript if block), vim throws an error that it can't find the terminating EOF as well as the endif statement.

[INFO] Editing '/home/mpenning/.vimrc'.
Error detected while processing /home/mpenning/.vimrc:
line  815:
E990: Missing end marker 'EOF'
  File "<string>", line 4
    EOF
IndentationError: unexpected indent
line  816:
E171: Missing :endif

Is there any problem with stripping off indentation inside the if-block for my "Working use-case"?

2 Answers 2

1

In the recent vim (I have 8.2.4975) there is a trim parameter and following works for me:

if has('python3')
    py3 << trim PYEND
        def hello(world):
            print(world)

        hello("world")
    PYEND
endif

I don't know when it was added though.

UPD Looks like it is quite old https://github.com/vim/vim/blame/c51cf0329809c7ae946c59d6f56699227efc9d1b/runtime/doc/if_pyth.txt#L779

0

Is there any problem with stripping off indentation inside the if-block for my "Working use-case"?

Indentation is helpful when reading vimscript, but indentation is not required. There is no mention of required indentation for this use-case in the vimscript documentation.

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.