summaryrefslogtreecommitdiffstats
path: root/ftplugin/mustache.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2014-02-04 19:15:58 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2014-02-04 19:15:58 +0100
commitd51b8fd17e3804f8d5ede68674b558174519abb2 (patch)
treed575d28b15cbc5a8a6cc7e106ef4fdbe47d9df30 /ftplugin/mustache.vim
parentfa573209195e94d621f50bfe37cf9007f6e8d720 (diff)
downloadvim-polyglot-1.5.2.tar.gz
vim-polyglot-1.5.2.zip
Change handlebars syntax vendor, fixes #13v1.5.2
Diffstat (limited to 'ftplugin/mustache.vim')
-rw-r--r--ftplugin/mustache.vim107
1 files changed, 107 insertions, 0 deletions
diff --git a/ftplugin/mustache.vim b/ftplugin/mustache.vim
new file mode 100644
index 00000000..38901654
--- /dev/null
+++ b/ftplugin/mustache.vim
@@ -0,0 +1,107 @@
+let s:cpo_save = &cpo
+set cpo&vim
+
+" Matchit support for Mustache & Handlebars
+" extending HTML matchit groups
+if exists("loaded_matchit") && exists("b:match_words")
+ let b:match_words = b:match_words
+ \ . ',{:},[:],(:),'
+ \ . '\%({{\)\@<=#\s*\%(if\|unless\)\s*.\{-}}}'
+ \ . ':'
+ \ . '\%({{\)\@<=\s*else\s*}}'
+ \ . ':'
+ \ . '\%({{\)\@<=/\s*\%(if\|unless\)\s*}},'
+ \ . '\%({{\)\@<=[#^]\s*\([-0-9a-zA-Z_?!/.]\+\).\{-}}}'
+ \ . ':'
+ \ . '\%({{\)\@<=/\s*\1\s*}}'
+endif
+
+if exists("g:mustache_abbreviations")
+ inoremap <buffer> {{{ {{{}}}<left><left><left>
+ inoremap <buffer> {{ {{}}<left><left>
+ inoremap <buffer> {{! {{!}}<left><left>
+ inoremap <buffer> {{< {{<}}<left><left>
+ inoremap <buffer> {{> {{>}}<left><left>
+ inoremap <buffer> {{# {{#}}<cr>{{/}}<up><left><left>
+ inoremap <buffer> {{if {{#if }}<cr>{{/if}}<up><left>
+ inoremap <buffer> {{ife {{#if }}<cr>{{else}}<cr>{{/if}}<up><up><left>
+endif
+
+
+" Section movement
+" Adapted from vim-ruby - many thanks to the maintainers of that plugin
+
+function! s:sectionmovement(pattern,flags,mode,count)
+ norm! m'
+ if a:mode ==# 'v'
+ norm! gv
+ endif
+ let i = 0
+ while i < a:count
+ let i = i + 1
+ " saving current position
+ let line = line('.')
+ let col = col('.')
+ let pos = search(a:pattern,'W'.a:flags)
+ " if there's no more matches, return to last position
+ if pos == 0
+ call cursor(line,col)
+ return
+ endif
+ endwhile
+endfunction
+
+nnoremap <silent> <buffer> [[ :<C-U>call <SID>sectionmovement('{{','b','n',v:count1)<CR>
+nnoremap <silent> <buffer> ]] :<C-U>call <SID>sectionmovement('{{','' ,'n',v:count1)<CR>
+xnoremap <silent> <buffer> [[ :<C-U>call <SID>sectionmovement('{{','b','v',v:count1)<CR>
+xnoremap <silent> <buffer> ]] :<C-U>call <SID>sectionmovement('{{','' ,'v',v:count1)<CR>
+
+
+" Operator pending mappings
+
+onoremap <silent> <buffer> ie :<C-U>call <SID>wrap_inside()<CR>
+onoremap <silent> <buffer> ae :<C-U>call <SID>wrap_around()<CR>
+xnoremap <silent> <buffer> ie :<C-U>call <SID>wrap_inside()<CR>
+xnoremap <silent> <buffer> ae :<C-U>call <SID>wrap_around()<CR>
+
+function! s:wrap_around()
+ " If the cursor is at the end of the tag element, move back
+ " so that the end tag can be detected.
+ while getline('.')[col('.')-1] ==# '}'
+ execute 'norm h'
+ endwhile
+
+ " Moves to the end of the closing tag
+ let pos = search('}}','We')
+ if pos != 0
+ if getline('.')[col('.')] ==# '}'
+ " Ending tag contains 3 closing brackets '}}}',
+ " move to the last bracket.
+ execute 'norm l'
+ endif
+
+ " select the whole tag
+ execute 'norm v%'
+ endif
+endfunction
+
+function! s:wrap_inside()
+ " If the cursor is at the end of the tag element, move back
+ " so that the end tag can be detected.
+ while getline('.')[col('.')-1] ==# '}'
+ execute 'norm h'
+ endwhile
+
+ " Moves to the end of the closing tag
+ let pos = search('}}','W')
+ if pos != 0
+ " select only inside the tag
+ execute 'norm v%loho'
+ endif
+endfunction
+
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
+" vim: nofoldenable