mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-07 03:04:27 +08:00
add doc
This commit is contained in:
104
zencoding.vim
104
zencoding.vim
@@ -5,11 +5,59 @@
|
|||||||
" Version: 0.1
|
" Version: 0.1
|
||||||
" WebPage: http://github.com/mattn/zencoding-vim
|
" WebPage: http://github.com/mattn/zencoding-vim
|
||||||
" Usage:
|
" Usage:
|
||||||
|
"
|
||||||
|
" Type abbreviation
|
||||||
|
" +-------------------------------------
|
||||||
|
" | html:5_
|
||||||
|
" +-------------------------------------
|
||||||
|
" "_" is a cursor position. and type <c-z>,
|
||||||
|
" +-------------------------------------
|
||||||
|
" | <!DOCTYPE HTML>
|
||||||
|
" | <html lang="${langfull}">
|
||||||
|
" | <head>
|
||||||
|
" | <title></title>
|
||||||
|
" | <meta charset="UTF-8">
|
||||||
|
" | </head>
|
||||||
|
" | <body>
|
||||||
|
" | _
|
||||||
|
" | </body>
|
||||||
|
" | </html>
|
||||||
|
" +-------------------------------------
|
||||||
|
" type following
|
||||||
|
" +-------------------------------------
|
||||||
|
" | div#foo$*2>div.bar
|
||||||
|
" +-------------------------------------
|
||||||
|
" and type <c-z>,
|
||||||
|
" +-------------------------------------
|
||||||
|
" | <div id="foo$">
|
||||||
|
" | <div class="bar">
|
||||||
|
" | </div>
|
||||||
|
" | </div>
|
||||||
|
" | _
|
||||||
|
" +-------------------------------------
|
||||||
|
"
|
||||||
" Tips:
|
" Tips:
|
||||||
|
"
|
||||||
|
" You can customize behaviour of expanding with overriding config.
|
||||||
|
" This configuration will be marged at loading plugin.
|
||||||
|
"
|
||||||
|
" let g:user_zen_settings = {
|
||||||
|
" \ 'indentation' : '_',
|
||||||
|
" \ 'perl' : {
|
||||||
|
" \ 'aliases' : {
|
||||||
|
" \ 'req' : 'require '
|
||||||
|
" \ },
|
||||||
|
" \ 'snippets' : {
|
||||||
|
" \ 'use' : "use strict\nuse warnings\n\n",
|
||||||
|
" \ 'warn' : "warn \"|\";",
|
||||||
|
" \ }
|
||||||
|
" \ }
|
||||||
|
" \}
|
||||||
|
"
|
||||||
" script type: plugin
|
" script type: plugin
|
||||||
|
|
||||||
if &cp || (exists('g:loaded_zencoding_vim') && g:loaded_zencoding_vim)
|
if &cp || (exists('g:loaded_zencoding_vim') && g:loaded_zencoding_vim)
|
||||||
"finish
|
finish
|
||||||
endif
|
endif
|
||||||
let g:loaded_zencoding_vim = 1
|
let g:loaded_zencoding_vim = 1
|
||||||
|
|
||||||
@@ -755,15 +803,15 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
if multiplier <= 0
|
if multiplier <= 0
|
||||||
let multiplier = 1
|
let multiplier = 1
|
||||||
endif
|
endif
|
||||||
if has_key(s:zen_settings[type], 'aliases')
|
if has_key(s:zen_settings[type], 'aliases')
|
||||||
if has_key(s:zen_settings[type]['aliases'], tag_name)
|
if has_key(s:zen_settings[type]['aliases'], tag_name)
|
||||||
let tag_name = s:zen_settings[type]['aliases'][tag_name]
|
let tag_name = s:zen_settings[type]['aliases'][tag_name]
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let current = { 'name': '', 'attr':[], 'child': [], 'snippet': '', 'multiplier': 1 }
|
let current = { 'name': '', 'attr':[], 'child': [], 'snippet': '', 'multiplier': 1 }
|
||||||
if has_key(s:zen_settings[type]['snippets'], tag_name)
|
if has_key(s:zen_settings[type]['snippets'], tag_name)
|
||||||
let current['snippet'] = s:zen_settings[type]['snippets'][tag_name]
|
let current['snippet'] = s:zen_settings[type]['snippets'][tag_name]
|
||||||
else
|
else
|
||||||
let current['name'] = tag_name
|
let current['name'] = tag_name
|
||||||
if has_key(s:zen_settings[type], 'default_attributes')
|
if has_key(s:zen_settings[type], 'default_attributes')
|
||||||
let default_attributes = s:zen_settings[type]['default_attributes']
|
let default_attributes = s:zen_settings[type]['default_attributes']
|
||||||
@@ -851,11 +899,14 @@ function! s:zen_toString(...)
|
|||||||
let str .= ">\n</" . current['name'] . ">\n"
|
let str .= ">\n</" . current['name'] . ">\n"
|
||||||
else
|
else
|
||||||
let str .= "></" . current['name'] . ">\n"
|
let str .= "></" . current['name'] . ">\n"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let str .= '' . current['snippet']
|
let str .= '' . current['snippet']
|
||||||
|
if len(str) == 0
|
||||||
|
let str = current['name']
|
||||||
|
endif
|
||||||
let inner = ''
|
let inner = ''
|
||||||
if len(current['child'])
|
if len(current['child'])
|
||||||
for n in current['child']
|
for n in current['child']
|
||||||
@@ -880,11 +931,11 @@ function! s:zen_expand()
|
|||||||
if expand !~ '|'
|
if expand !~ '|'
|
||||||
let expand .= '|'
|
let expand .= '|'
|
||||||
endif
|
endif
|
||||||
silent! exec "normal! ".repeat("x", len(part))
|
silent! exec "normal! ".repeat("x", len(part))
|
||||||
let size = len(line) - len(part)
|
let size = len(line) - len(part)
|
||||||
let indent = repeat(s:zen_settings['indentation'], size)
|
let indent = repeat(s:zen_settings['indentation'], size)
|
||||||
let expand = indent . substitute(expand, "\n", "\n" . indent, 'g')
|
let expand = indent . substitute(expand, "\n", "\n" . indent, 'g')
|
||||||
silent! put! =expand
|
silent! put! =expand
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
return '|'
|
return '|'
|
||||||
@@ -899,6 +950,32 @@ endfunction
|
|||||||
inoremap <plug>ZenCodingExpand <c-r>=<sid>zen_expand()<cr><esc>?\|<cr>a<bs>
|
inoremap <plug>ZenCodingExpand <c-r>=<sid>zen_expand()<cr><esc>?\|<cr>a<bs>
|
||||||
imap <c-z>, <plug>ZenCodingExpand
|
imap <c-z>, <plug>ZenCodingExpand
|
||||||
|
|
||||||
|
function! s:zen_mergeConfig(lhs, rhs)
|
||||||
|
if type(a:lhs) == 3 && type(a:rhs) == 3
|
||||||
|
call remove(a:lhs, 0, len(a:lhs)-1)
|
||||||
|
for index in a:rhs
|
||||||
|
call add(a:lhs, a:rhs[index])
|
||||||
|
endfor
|
||||||
|
elseif type(a:lhs) == 4 && type(a:rhs) == 4
|
||||||
|
for key in keys(a:rhs)
|
||||||
|
if type(a:rhs[key]) == 3
|
||||||
|
call s:zen_mergeConfig(a:lhs[key], a:rhs[key])
|
||||||
|
elseif type(a:rhs[key]) == 4
|
||||||
|
if has_key(a:lhs, key)
|
||||||
|
call s:zen_mergeConfig(a:lhs[key], a:rhs[key])
|
||||||
|
else
|
||||||
|
let a:lhs[key] = a:rhs[key]
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let a:lhs[key] = a:rhs[key]
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
if exists('g:user_zen_settings')
|
||||||
|
call s:zen_mergeConfig(s:zen_settings, g:user_zen_settings)
|
||||||
|
endif
|
||||||
" test
|
" test
|
||||||
"echo ZenExpand('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '')
|
"echo ZenExpand('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '')
|
||||||
"echo ZenExpand('ol>li*2', '')
|
"echo ZenExpand('ol>li*2', '')
|
||||||
@@ -907,3 +984,6 @@ imap <c-z>, <plug>ZenCodingExpand
|
|||||||
"echo ZenExpand('cc:ie6>p+blockquote#sample$.so.many.classes*2', '')
|
"echo ZenExpand('cc:ie6>p+blockquote#sample$.so.many.classes*2', '')
|
||||||
"echo ZenExpand('tm>if>div.message', '')
|
"echo ZenExpand('tm>if>div.message', '')
|
||||||
"echo ZenExpand('@i', 'css')
|
"echo ZenExpand('@i', 'css')
|
||||||
|
"echo ZenExpand('req', 'perl')
|
||||||
|
|
||||||
|
" vim:set et:
|
||||||
|
|||||||
Reference in New Issue
Block a user