Skip to content

Commit

Permalink
add plugin endtagcomment.vim
Browse files Browse the repository at this point in the history
  • Loading branch information
seventhsense committed Nov 23, 2016
1 parent 5c2af12 commit 58b2610
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 58 deletions.
58 changes: 0 additions & 58 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -494,64 +494,6 @@ au FileType ruby,eruby setl tags+=~/gtags
""vim-eco
autocmd BufNewFile,BufRead *.eco set filetype=eco

" endtagcomment.vim
" https://gist.github.com/hokaccha/4118281
" こういう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>
""filetype cucumber
au BufRead,BufNewFile *_steps.rb set filetype=cucumber.ruby

Expand Down
5 changes: 5 additions & 0 deletions dein.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ hook_add = '''
nmap <Leader>c <Plug>NERDCommenterToggle
vmap <Leader>c <Plug>NERDCommenterToggle
'''
[[plugins]]
repo = 'haya14busa/endtagcomment.vim'
hook_add = '''
nmap ,t <Plug>(endtagcomment)
'''

## movement plugins
[[plugins]] # $BBP1~$9$k%+%C%3$K0\F0(B
Expand Down

0 comments on commit 58b2610

Please sign in to comment.