38

I've been using LESS and I find it very useful

I would like to have CSS syntax highlight in Vim with all .less files.

Any suggestions?

4 Answers 4

37

http://leafo.net/lessphp/vim/

Check the INSTALL file for instructions.

2
  • 2
    Would be useful if you provided the actual information in the answer and not only a link meta.stackexchange.com/questions/8231/…
    – Nilzor
    May 13, 2014 at 9:14
  • You should quote the explanation, paraphrase it, or add your own explanation rather than post a link to it. If the link one day becomes broken, your answer is no longer helpful. In fact the link seems to be broken as I write this comment.
    – Alexandre
    Nov 17, 2022 at 11:42
20

There are also a couple of github repos:

2
  • 5
    groenewege/vim-less is working better for me than lunaru's and lessphp's.
    – Jo Liss
    Nov 21, 2011 at 3:16
  • 2
    as jo liss says, groenewege is what you want. it goes nicely with two other plugins. if you have pathogen installed, you can just run these three git commands in your ~/.vim/bundle directory: git clone https://github.com/skammer/vim-css-color.git git clone https://github.com/groenewege/vim-less git clone https://github.com/hail2u/vim-css3-syntax Dec 24, 2013 at 0:27
13

If you only want to use Vim's syntax highlighting, then you can set the filetype of every LESS file to be a CSS file.

To do this, you can add au BufNewFile,BufRead *.less set filetype=css to your .vimrc file.

au stands for autocommand, so the above line reads "on events BufNewFile or BufRead, if the file has a less extension, then set the filetype option to css".

Keep in mind that this is not the recommended way. According to the Vim tips Wiki:

If there is a new file extension that you want Vim to recognize, don't muck about with augroup in your .vimrc, put the settings in the right place. See :help ftdetect

1
  • 1
    The other reason not to do this is that there are aspects of less that vim's css syntax highlighting (correctly) considers wrong - for example nested curly braces
    – pho79
    Aug 30, 2012 at 19:54
4

Paste this line into your .vimrc:

au BufRead,BufNewFile *.less setfiletype css

au is a shorthand for autocmd. So this reads as "when I read or open a new file that ends in .less, automatically set the filetype as CSS".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.