如何正确制作vim格式的源代码

时间:2022-07-26 22:48:32

I'm trying to use vim to edit source code for AutoHotkey.

我正在尝试使用vim编辑AutoHotkey的源代码。

This is how the source code looks when correctly formatted:

这是正确格式化时源代码的外观:

if foo
{
    if bar = 1
        callFunc1()
    if bar = 2
        callFunc2() 
    if bar = 3
        callFunc3()
}

If I do =G, then this is what vim changes it to:

如果我做= G,那么这就是vim将其更改为:

if foo
{
    if bar = 1
        callFunc1()
        if bar = 2
            callFunc2() 
            if bar = 3
                callFunc3()
}

I had other formatting problems with this source code that was solved by using :set cindent cinoptions=+0, but that does not solve this problem.

我有这个源代码的其他格式问题,通过使用:set cindent cinoptions = + 0解决,但这并没有解决这个问题。

2 个解决方案

#1


0  

cindent is generally for C... There are lot of vim extensions for various programming languages, google for them. They often introduce proper syntax indentation.

cindent通常用于C ...各种编程语言有很多vim扩展,谷歌为他们。它们经常引入适当的语法缩进。

#2


0  

If there's no indent file for this kind of script, you can use the indentAnything script.

如果此类脚本没有缩进文件,则可以使用indentAnything脚本。

As stated :

就像声明的那样 :

The IndentAnything plugin is intended to make it easier to write new indentation scripts and/or supplement existing ones. It makes the assumption that all indentable languages have similar characteristics:

IndentAnything插件旨在使编写新的缩进脚本和/或补充现有脚本更容易。它假设所有可压缩语言都具有类似的特征:

  • blocks of code or text over multiple lines
  • 多行代码或文本块

  • continuation lines
  • comments

#1


0  

cindent is generally for C... There are lot of vim extensions for various programming languages, google for them. They often introduce proper syntax indentation.

cindent通常用于C ...各种编程语言有很多vim扩展,谷歌为他们。它们经常引入适当的语法缩进。

#2


0  

If there's no indent file for this kind of script, you can use the indentAnything script.

如果此类脚本没有缩进文件,则可以使用indentAnything脚本。

As stated :

就像声明的那样 :

The IndentAnything plugin is intended to make it easier to write new indentation scripts and/or supplement existing ones. It makes the assumption that all indentable languages have similar characteristics:

IndentAnything插件旨在使编写新的缩进脚本和/或补充现有脚本更容易。它假设所有可压缩语言都具有类似的特征:

  • blocks of code or text over multiple lines
  • 多行代码或文本块

  • continuation lines
  • comments