如何在 vim 中基于大括号定义缩进?
我使用 https://github.com/cakebaker/scss-syntax.vim vim 上的语法高亮 SCSS (或 SASS)文件,这对于语法高亮非常有效。但是,该插件没有附带缩进文件,并且我在编写缩进文件时遇到了麻烦。
我想将缩进设置为如下所示:
但是,如果我这样做 gg= G
,我得到:
我怀疑它不理解基于大括号的嵌套缩进。 的所有不同组合
我尝试了set cindent
set nocindent
set autoindent
set smartindent
,并尝试使用以下代码Tab 键 == 4 个空格和 auto -Vim 中大括号后缩进 ,包括
set tabstop=2
set shiftwidth=2
set Expandtab
...但嵌套大括号缩进似乎永远不起作用。
我相信我可能想编写一个自定义缩进文件,而我所需要的只是基于具有嵌套级别的大括号的缩进。我该怎么办?如果有人有一个具有类似语法的文件类型的缩进文件,那也很好。
I use https://github.com/cakebaker/scss-syntax.vim for syntax highlighting SCSS (or SASS) files on vim, which works very well for syntax highlighting. However, the plugin does not come with an indent file and am having trouble writing one.
I would like to set the indent to look like this:
However, if i do gg=G
, I get:
I suspect that it does not understand nested indent based on braces. I tried all the different combinations of
set cindent
set nocindent
set autoindent
set smartindent
and tried to use the code from Tab key == 4 spaces and auto-indent after curly braces in Vim , including
set tabstop=2
set shiftwidth=2
set expandtab
...but nested braces indent never seems to work.
I believe that I might want to write a custom indent file, and all I need is indentation based on braces with nested levels. How should I go about this? If someone has an indentation file for filetypes with similar syntax, that will be great as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个基于内置 perl 缩进代码(在
indent/perl.vim
中)的快速破解。希望你能用它来实现你想做的事。有关更多详细信息,请参阅 perl 缩进代码或缩进目录中的另一个文件中的更详细注释。将该文件另存为
~/.vim/indent/something.vim
,其中something
是您的文件类型(将~/.vim
替换为路径如果您在 Windows 上,您可能还想将其粘贴到
vimfiles
中(但前提是没有可能首先加载的其他缩进声明):This is a quick hack, based on the built-in perl indentation code (in
indent/perl.vim
). Hopefully you can use it to get what you want to do. See the more detailed comments in either the perl indentation code or another one of the files in the indent directory for more details.Save that file as
~/.vim/indent/something.vim
wheresomething
is your file type (replace~/.vim
with the path tovimfiles
if you're on Windows.You might also want to stick this at the start of the file (but only if there isn't some other indent declaration that might be loaded first):