简体   繁体   中英

Vim: Pascal autoindent

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"?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM