Last active
October 3, 2016 16:42
-
-
Save HerringtonDarkholme/c97d35b1d21e3860f5b46f2a947ffcf2 to your computer and use it in GitHub Desktop.
vue syntax highlighting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim syntax file | |
" Language: Vue.js | |
" Maintainer: Eduardo San Martin Morote | |
if exists("b:current_syntax") | |
finish | |
endif | |
if !exists("s:syntaxes") | |
" Search available syntax files. | |
function s:search_syntaxes(...) | |
let syntaxes = {} | |
let names = a:000 | |
for name in names | |
let syntaxes[name] = 0 | |
endfor | |
for path in split(&runtimepath, ',') | |
if isdirectory(path . '/syntax') | |
for name in names | |
let syntaxes[name] = syntaxes[name] || filereadable(path . '/syntax/' . name . '.vim') | |
endfor | |
endif | |
endfor | |
return syntaxes | |
endfunction | |
let s:syntaxes = s:search_syntaxes('pug', 'coffee', 'stylus', 'sass', 'scss', 'less', 'typescript') | |
endif | |
syn keyword vueTagName contained script style | |
syn region vueEndTag start=+</+ end=+>+ contains=vueTagName | |
syn region vueStartTag start=+^<script+ end=+>+ contains=vueTagName | |
syn region vueStartTag start=+^<style+ end=+>+ contains=vueTagName | |
highlight link vueTagName htmlSpecialTagName | |
syntax include @HTML syntax/html.vim | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
syntax region template keepend start=/^<template>/ end=/^<\/template>/ contains=@HTML fold | |
if s:syntaxes.pug | |
syntax include @PUG syntax/pug.vim | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
syntax region pug keepend start=/<template lang="[^"]*pug[^"]*">/ end="</template>" contains=@PUG fold | |
syntax region pug keepend start=/<template lang="[^"]*jade[^"]*">/ end="</template>" contains=@PUG fold | |
endif | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
if s:syntaxes.typescript | |
runtime! syntax/typescript.vim | |
" syntax include @TS syntax/typescript.vim | |
" syntax region script start=/<script\( lang="ts"\)\?\( type="vue-ts"\)\?>/ keepend end="</script>"me=s-1 contains=@TS,vueStartTag fold | |
else | |
syntax include @JS syntax/javascript.vim | |
syntax region script start=/<script\( lang="babel"\)\?\( type="text\/babel"\)\?>/ keepend end="</script>"me=s-1 contains=@JS,vueStartTag fold | |
endif | |
if s:syntaxes.coffee | |
syntax include @COFFEE syntax/coffee.vim | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
" Matchgroup seems to be necessary for coffee | |
syntax region coffee matchgroup=Delimiter start="<script lang=\"coffee\">" end="</script>" contains=@COFFEE fold | |
endif | |
syntax include @CSS syntax/css.vim | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
syntax region style keepend start=/^<style\( \+scoped\)\?>/ end="</style>"me=s-1 contains=@CSS,vueStartTag fold | |
if s:syntaxes.stylus | |
syntax include @stylus syntax/stylus.vim | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
syntax region stylus keepend start=/<style lang="[^"]*stylus[^"]*"\( \+scoped\)\?>/ end="</style>" contains=@stylus fold | |
endif | |
if s:syntaxes.sass | |
syntax include @sass syntax/sass.vim | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
syntax region sass keepend start=/<style\( \+scoped\)\? lang="[^"]*sass[^"]*"\( \+scoped\)\?>/ end="</style>" contains=@sass fold | |
endif | |
if s:syntaxes.scss | |
syntax include @scss syntax/scss.vim | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
syntax region scss keepend start=/<style\( \+scoped\)\? lang="[^"]*scss[^"]*"\( \+scoped\)\?>/ end="</style>" contains=@scss fold | |
endif | |
if s:syntaxes.less | |
syntax include @less syntax/less.vim | |
if exists("b:current_syntax") | |
unlet b:current_syntax | |
endif | |
syntax region less keepend matchgroup=PreProc start=/<style\%( \+scoped\)\? lang="less"\%( \+scoped\)\?>/ end="</style>" contains=@less fold | |
endif | |
let b:current_syntax = "vue" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment