vim 中混乱的 css 缩进
在vim中编辑html文件时,style
标签内的css缩进很混乱。
例如,这就是它如何缩进此示例 css 代码,而无需任何手动干预来修复我的缩进:
div.class
{
color: white;
backgroung-color: black;
}
为什么会发生这种情况?我该如何修复它?
When editing an html file in vim, the indentation for css inside style
tags is messy.
For instance, this is how it would indent this sample css code without any manual intervention to fix the indentation on my part:
div.class
{
color: white;
backgroung-color: black;
}
Why is this happening? how can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我遇到了同样的问题,无法真正提供帮助,但我倾向于做的是
vi{
然后9<<
最后>>
。我试图找到一个好的 css 缩进,但我尝试过的似乎都不能正常工作。
I experience the same problem, can't really help but I tend to do is
vi{
then9<<
and finally>>
.I tried to find a good css indent, but none of the ones I tried seemed to work properly.
这个缩进脚本似乎工作得很好(更好)。
下载它并将其粘贴到
~/.vim/indent/css.vim
您将需要
.vimrc
中的filetype 插件 indent on
行> 按照 kamaji 的建议,也归档。现在,如果我只能让它在 .css.less 文件上工作......
This indent script seems to work well (better).
Download it and stick it at
~/.vim/indent/css.vim
You'll need the
filetype plugin indent on
line in your.vimrc
file, too, as kamaji suggests.Now if I could only get it working on .css.less files...
尝试使用 this html 文件类型缩进脚本。它改进了对样式标签的支持。众所周知,HTML 页面中的 Javascript 和 CSS 缩进处理对于 Vim 中的 html 缩进来说是有问题的。我还没有找到一个能完美完成所有事情的脚本。
Try using this html filetype indent script instead. It has improved support for style tags. Javascript and CSS indent handling in HTML pages is known to be problematic with the html indentation in Vim. I've yet to find a script that does everything perfectly.
我也有类似的问题。
我的解决方案是编辑(备份后)全局“vimrc”文件并取消注释以下行,方法是删除每行开头的双引号:
我还在本地“~/.vimrc”中设置了“set cindent”文件,所以我删除了它。
似乎工作正常。
I was having a similar problem.
My solution was to edit (after backing up) the global 'vimrc' file and uncomment the following lines, by removing the double quotes at the start of each line:
I also had 'set cindent' in my local '~/.vimrc' file so I removed that.
Seems to be working fine.
一种解释可能是文件中混合了制表符和空格。
(尽管问题中的出现可能更多是由于 Markdown 而不是其他原因)
One explanation might be that you have a mixture of TABs and spaces in the file.
(Although the appearance in the question may be more due to Markdown than anything else)
就我而言,问题是由于
cindent
引起的。在.vimrc
(或.gvimrc
,...)中找到以下行并将其删除。然后你就可以走了。最后,如果您既是网页开发人员又是内核开发人员,您也许可以使用如下所示的映射来打开和关闭
cindent
In my case the problem is because of
cindent
. Find the following line in your.vimrc
(or.gvimrc
, ...) and remove it.Then you are good to go. Lastly if you are both a web page developer and kernel developer you can perhaps use a mapping like bellow to toggle
cindent
on and off