English 中文(简体)
messy css indentation in vim
原标题:

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?

问题回答

I experience the same problem, can t really help but I tend to do is vi{ then 9<< and finally >>. I tried to find a good css indent, but none of the ones I tried seemed to work properly.

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...

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.

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:

"if has("autocmd")
"  filetype plugin indent on
"endif

I also had set cindent in my local ~/.vimrc file so I removed that.

Seems to be working fine.

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)

In my case the problem is because of cindent. Find the following line in your .vimrc (or .gvimrc, ...) and remove it.

set cindent

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

map <F8> :set cindent!<CR>




相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签