Created
May 24, 2010 13:03
-
-
Save hokaccha/411828 to your computer and use it in GitHub Desktop.
This file contains 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
" こういうHTMLがあったときに | |
" <div id="hoge" class="fuga"> | |
" ... | |
" </div> | |
" | |
" 実行するとこうなる | |
" <div id="hoge" class="fuga"> | |
" ... | |
" <!-- /div#hoge.fuga --></div> | |
function! Endtagcomment() | |
let reg_save = @@ | |
try | |
silent normal vaty | |
catch | |
execute "normal \<Esc>" | |
echohl ErrorMsg | |
echo 'no match html tags' | |
echohl None | |
return | |
endtry | |
let html = @@ | |
let start_tag = matchstr(html, '\v(\<.{-}\>)') | |
let tag_name = matchstr(start_tag, '\v([a-zA-Z]+)') | |
let id = '' | |
let id_match = matchlist(start_tag, '\vid\=["'']([^"'']+)["'']') | |
if exists('id_match[1]') | |
let id = '#' . id_match[1] | |
endif | |
let class = '' | |
let class_match = matchlist(start_tag, '\vclass\=["'']([^"'']+)["'']') | |
if exists('class_match[1]') | |
let class = '.' . join(split(class_match[1], '\v\s+'), '.') | |
endif | |
execute "normal `>va<\<Esc>`<" | |
let comment = g:endtagcommentFormat | |
let comment = substitute(comment, '%tag_name', tag_name, 'g') | |
let comment = substitute(comment, '%id', id, 'g') | |
let comment = substitute(comment, '%class', class, 'g') | |
let @@ = comment | |
normal ""P | |
let @@ = reg_save | |
endfunction | |
let g:endtagcommentFormat = '<!-- /%tag_name%id%class -->' | |
nnoremap ,t :<C-u>call Endtagcomment()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
素晴らしい設定をありがとうございます。
閉じタグの直前ではなく直後に入れるにはどこを設定したら良いでしょうか?
教えていただけますか?