Skip to content

Instantly share code, notes, and snippets.

@kosei27
Forked from hokaccha/endtagcomment.vim
Created December 9, 2010 07:35
Show Gist options
  • Select an option

  • Save kosei27/734448 to your computer and use it in GitHub Desktop.

Select an option

Save kosei27/734448 to your computer and use it in GitHub Desktop.
function! g:endtagcomment()
let tmp = @@
let tmp_pos = getpos('.')
silent normal vaty
let html = @@
let start_tag = matchstr(html, '\v(\<.{-}\>)')
let tag_name = matchstr(start_tag, '\v([a-zA-Z]+)')
let id_m = matchlist(start_tag, '\vid\=["'']([^"'']+)["'']')
let id = ''
if exists('id_m[1]')
let id = '#' . id_m[1]
endif
let class_m = matchlist(start_tag, '\vclass\=["'']([^"'']+)["'']')
let class = ''
if exists('class_m[1]')
let class = '.' . join(split(class_m[1], '\v\s+'), '.')
endif
call setpos('.', tmp_pos)
let @@ = printf('<!-- /%s%s%s -->', tag_name, id, class)
normal ""P
let @@ = tmp
endfunction
nnoremap ,t :<C-u>call g:endtagcomment()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment