0

I have a problem with Pascal auto-indentation in Vim.

begin
    writeln('Hello World');
    end.

Vim do not indent end. . However if there is end; it is indented properly.

When I perform gg=G whole code is indented properly. Is there a way to make Vim to use command like gg=G "on the run"?

3
  • I have no idea what you are asking.
    – FDinoff
    Jul 5, 2014 at 0:08
  • @Fdinoff, the end. tokens should be indented such that they start at the same column as begin. According to this description, it gets indented properly when end is followed by a semicolon, but not when it's followed by a period. A period marks the end of the current file, so it occurs seldom compared to other begin-end pairs in a program, and maybe that detail was neglected in Vim's Pascal syntax file. Jul 5, 2014 at 2:09
  • @RobKennedy Ok thanks for the explanation. It was neglected in Vim's Pascal indent file.
    – FDinoff
    Jul 5, 2014 at 3:50

1 Answer 1

3

Yeah seems to be an oversight. (You should go file a bug report, you can find the maintainer of the script at the top of file located at $VIMRUNTIME/indent/pascal.vim)

You just need to append =end. to indentkeys. indentkeys controls when vim should try and reindent the current line. To do this add setlocal indentkeys+==end. to the file ~/.vim/after/indent/pascal.vim (You will need to create the file and the directories if they do not exist)

This file will get sourced after the normal indent script gets sourced which is what you want.

Take a look at :h indentkeys and :h after


Side note: gg=G reindents the whole file but it is not a single command. It is actually two different ones. gg which is move to the top of the file and ={motion} which is reindent from the current line to the end of the motion. The {motion} in this case to go to the end of the file. So we reindent the whole file.

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.