├── .gitignore ├── README.md ├── after └── syntax │ └── html.vim ├── ftdetect └── less.vim ├── ftplugin └── less.vim ├── indent └── less.vim ├── screenshot.png └── syntax └── less.vim /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VIM-LESS 2 | 3 | This vim bundle adds syntax highlighting, indenting and autocompletion for the dynamic stylesheet language [LESS](http://lesscss.org). 4 | 5 | This bundle is compatible with [vim-css-color](https://github.com/skammer/vim-css-color), 6 | [vim-css3-syntax](https://github.com/hail2u/vim-css3-syntax) and possibly other plugins that place code 7 | in `after/syntax/css.vim` or `after/syntax/css/*.vim`. 8 | 9 | ![vim-less with vim-css-color and vim-css3-syntax (colorscheme solarized)](https://github.com/lenniboy/vim-less/raw/master/screenshot.png) 10 | 11 | 12 | ## Installing and Using 13 | 14 | - Install [pathogen](http://www.vim.org/scripts/script.php?script_id=2332) into `~/.vim/autoload/` and add the 15 | following line to your `~/.vimrc`: 16 | 17 | call pathogen#infect() 18 | 19 | - Make a clone of the `vim-less` repository: 20 | 21 | $ mkdir -p ~/.vim/bundle 22 | $ cd ~/.vim/bundle 23 | $ git clone https://github.com/groenewege/vim-less 24 | 25 | - OR use [vundle](https://github.com/gmarik/vundle), adding this line to your `~/.vimrc`: 26 | 27 | Plugin 'groenewege/vim-less' 28 | 29 | 30 | - OR use [neobundle](https://github.com/Shougo/neobundle.vim), adding this line to your `~/.vimrc`: 31 | 32 | NeoBundle 'groenewege/vim-less' 33 | 34 | 35 | - OR use git submodules: 36 | 37 | $ git submodule add https://github.com/groenewege/vim-less.git bundle/vim-less 38 | $ git submodule init 39 | 40 | 41 | ### Map 42 | .less to .css , lessc is required. 43 | 44 | nnoremap m :w !lessc % > %:t:r.css 45 | 46 | 47 | ## Credits 48 | 49 | Inspiration from [vim-haml](https://github.com/tpope/vim-haml), 50 | [scss-syntax.vim](https://github.com/cakebaker/scss-syntax.vim) and 51 | [vim-less](https://github.com/lunaru/vim-less) 52 | 53 | ## License ## 54 | 55 | MIT : [groenewege.mit-license.org](http://groenewege.mit-license.org/) 56 | -------------------------------------------------------------------------------- /after/syntax/html.vim: -------------------------------------------------------------------------------- 1 | if !exists("g:less_html_style_tags") 2 | let g:less_html_style_tags = 1 3 | endif 4 | 5 | if !g:less_html_style_tags 6 | finish 7 | endif 8 | 9 | " Unset (but preserve) so that less will run. 10 | if exists("b:current_syntax") 11 | let s:pre_less_cur_syn = b:current_syntax 12 | unlet b:current_syntax 13 | endif 14 | 15 | " Inspired by code from github.com/kchmck/vim-coffee-script 16 | " and the html syntax file included with vim 7.4. 17 | 18 | syn include @htmlLess syntax/less.vim 19 | 20 | " We have to explicitly add to htmlHead (containedin) as that region specifies 'contains'. 21 | syn region lessStyle start=++ contains=@htmlLess,htmlTag,htmlEndTag,htmlCssStyleComment,@htmlPreproc containedin=htmlHead 22 | 23 | " Reset since 'less' isn't really the current_syntax. 24 | if exists("s:pre_less_cur_syn") 25 | let b:current_syntax = s:pre_less_cur_syn 26 | endif 27 | -------------------------------------------------------------------------------- /ftdetect/less.vim: -------------------------------------------------------------------------------- 1 | autocmd BufNewFile,BufRead *.less setf less 2 | -------------------------------------------------------------------------------- /ftplugin/less.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin 2 | " Language: LessCSS 3 | " Author: Tim Pope 4 | " Maintainer: Leonard Ehrenfried 5 | " Last Change: 2011 Sep 30 6 | 7 | " Only do this when not done yet for this buffer 8 | if exists("b:did_ftplugin") 9 | finish 10 | endif 11 | let b:did_ftplugin = 1 12 | 13 | let b:undo_ftplugin = "setl cms< def< inc< inex< ofu< sua<" 14 | 15 | setlocal iskeyword+=- 16 | setlocal commentstring=//%s 17 | setlocal define=^\\s*\\%(@mixin\\\|=\\) 18 | setlocal includeexpr=substitute(v:fname,'\\%(.*/\\\|^\\)\\zs','_','') 19 | setlocal omnifunc=csscomplete#CompleteCSS 20 | setlocal suffixesadd=.less 21 | setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,:// 22 | setlocal fo=croql 23 | 24 | let &l:include = '^\s*@import\s\+\%(url(\)\=["'']\=' 25 | 26 | " vim:set sw=2: 27 | -------------------------------------------------------------------------------- /indent/less.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: LessCSS 3 | " Maintainer: Leonard Ehrenfried 4 | " Last Change: 2011 Sep 26 5 | 6 | if exists("b:did_indent") 7 | finish 8 | endif 9 | 10 | runtime! indent/css.vim -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/groenewege/vim-less/6e818d5614d5fc18d95a48c92b89e6db39f9e3d6/screenshot.png -------------------------------------------------------------------------------- /syntax/less.vim: -------------------------------------------------------------------------------- 1 | if exists("b:current_syntax") 2 | finish 3 | endif 4 | 5 | runtime! syntax/css.vim 6 | runtime! after/syntax/css.vim 7 | " load files from vim-css3-syntax plugin (https://github.com/hail2u/vim-css3-syntax) 8 | runtime! after/syntax/css/*.vim 9 | 10 | syn case ignore 11 | 12 | syn region lessDefinition transparent matchgroup=cssBraces start='{' end='}' contains=css.*Attr,css.*Prop,cssComment,cssValue.*,cssColor,cssTagName,cssPseudoClass,cssUrl,cssImportant,cssError,cssStringQ,cssStringQQ,cssFunction,cssUnicodeEscape,lessDefinition,lessComment,lessClassChar,lessVariable,lessMixinChar,lessAmpersandChar,lessFunction,lessNestedSelector,@cssColors fold 13 | 14 | syn match lessVariable "@[[:alnum:]_-]\+" contained 15 | syn match lessVariable "@[[:alnum:]_-]\+" nextgroup=lessVariableAssignment skipwhite 16 | syn match lessVariableAssignment ":" contained nextgroup=lessVariableValue skipwhite 17 | syn match lessVariableValue ".*;"me=e-1 contained contains=lessVariable,lessOperator,lessDefault,cssValue.*,@cssColors "me=e-1 means that the last char of the pattern is not highlighted 18 | 19 | syn match lessOperator "+" contained 20 | syn match lessOperator "-" contained 21 | syn match lessOperator "/" contained 22 | syn match lessOperator "*" contained 23 | 24 | syn match lessNestedSelector "[^/]* {"me=e-1 contained contains=cssTagName,cssAttributeSelector,lessAmpersandChar,lessVariable,lessMixinChar,lessFunction,lessNestedProperty 25 | syn match lessNestedProperty "[[:alnum:]]\+:"me=e-1 contained 26 | 27 | syn match lessDefault "!default" contained 28 | 29 | syn match lessMixinChar "\.[[:alnum:]_-]\@=" contained nextgroup=lessClass 30 | syn match lessAmpersandChar "&" contained nextgroup=lessClass,cssPseudoClass 31 | syn match lessClass "[[:alnum:]_-]\+" contained 32 | 33 | " functions {{{ 34 | 35 | " string functions 36 | syn keyword lessFunction escape e % containedin=cssDefinition contained 37 | " misc functions 38 | syn keyword lessFunction unit containedin=cssDefinition contained 39 | " math functions 40 | syn keyword lessFunction ceil floor percentage round containedin=cssDefinition contained 41 | " color definition 42 | syn keyword lessFunction rgb rgba argb hsl hsla hsv hsva containedin=cssDefinition contained 43 | " color channel information 44 | syn keyword lessFunction hue saturation lightness red green blue alpha luma containedin=cssDefinition contained 45 | " color operations 46 | syn keyword lessFunction saturate desaturate lighten darken fadein fadeout fade spin mix greyscale contrast containedin=cssDefinition contained 47 | " color blending 48 | syn keyword lessFunction multiply screen overlay softlight hardlight difference exclusion average negation containedin=cssDefinition contained 49 | 50 | " }}} 51 | 52 | syn match lessComment "//.*$" contains=@Spell 53 | 54 | hi def link lessVariable Special 55 | hi def link lessVariableValue Constant 56 | hi def link lessDefault Special 57 | hi def link lessComment Comment 58 | hi def link lessFunction Function 59 | hi def link lessMixinChar Special 60 | hi def link lessAmpersandChar Special 61 | hi def link lessNestedProperty Type 62 | hi def link lessClass PreProc 63 | 64 | let b:current_syntax = "less" 65 | --------------------------------------------------------------------------------