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?

alexchenco
  • 53,565
  • 76
  • 241
  • 413

4 Answers4

37

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

Check the INSTALL file for instructions.

reko_t
  • 55,302
  • 10
  • 87
  • 77
  • 2
    Would be useful if you provided the actual information in the answer and not only a link http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers – Nilzor May 13 '14 at 09: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 '22 at 11:42
20

There are also a couple of github repos:

scribu
  • 2,958
  • 4
  • 34
  • 44
  • 5
    groenewege/vim-less is working better for me than lunaru's and lessphp's. – Jo Liss Nov 21 '11 at 03: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` – Orwellophile Dec 24 '13 at 00: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

reacuna
  • 463
  • 9
  • 17
  • 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 '12 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".

Gordon
  • 41
  • 2