" Html macros and mappings for: " ----------------------------- " " * Closing an opening tag " * Wrapping text with tags " * Increasing the weight of header tags (

...) " * Formatting text inside a pair of tags " * Rearranging content vertically " * Stripping outer tags " * 'Spacing' vertically the content of a pair of tags " " Rem: Use zR to unfold everything, then read :help folding " " Notes {{{1 " " Author: Dimitar Dimitrov (mitkofr@yahoo.fr), kurkale6ka " " Note: Start with :se ft=html for any text where you want to use these " macros. The indenting will be done better " " Note: Install in: " ~/.vim/ftplugin/html.vim " ln -s ~/.vim/ftplugin/html.vim phtml.vim " ln -s ~/.vim/ftplugin/html.vim xml.vim " " Note: @u, @o, \u and \o make use of " Tabular.vim and myTabularMaps.vim " http://github.com/godlygeek/tabular/tree/master " " myTabularMaps.vim must at least contain these two lines: " " AddTabularPipeline! html /\%(<[^<>?!]*>.\{-}\)\@?!]*>/ tabular#TabularizeStrings(a:lines, '\%(<[^<>?!]*>.\{-}\)\@?!]*>' , 'l1') " \ | tabular#TabularizeStrings(a:lines, '<\/\a\+>\%(.\{-}<\/\a\+>\)\@!', 'l1') " " Note: \g, \r, \x and \m don't work on nested " and " and can't be used while positioned on the first char in the file " " Note: If you must use @u, @o, @p, @d or \u, \o till the eof, " be 'careful' to add an empty line at the eof " " Note: 7@p won't work if one of the paragraphs starts with a one letter word " (ex: I). Same for <> 7 or another macro or on words. " }}}1 " 1. Close an opening tag {{{1 " ---------------------------- " " >> : newline (write quickly a second > after the first one) " >/ : " " " 2. Wrapping: {{{1 " ----------------- " " +-----------+-------------------+ " | paragraph | WORD or selection | " +-------+-----------+-------------------+ " |

\+EB" nnoremap \£h ciW:exe 'norm a' . b:h1_class . "> \evitholp2EB" vnoremap \h c:exe 'norm a' . b:h1_class . "> \evitholgpvatov:s/\\s\\+$//ge\r=atvatv" endfunction function! Init_i() let @i="i\`[2Ei" endfunction function! Init_em() let @e="I \ \+EB" nnoremap \£e ciW:exe 'norm a' . b:em_class . "> \evitholp2EB" vnoremap \e c:exe 'norm a' . b:em_class . "> \evitholgpvatov:s/\\s\\+$//ge\r=atvatv" endfunction function! Init_b() let @b="I \ \+EB" nnoremap \£b ciW:exe 'norm a' . b:b_class . "> \evitholp2EB" vnoremap \b c:exe 'norm a' . b:b_class . "> \evitholgpvatov:s/\\s\\+$//ge\r=atvatv" endfunction function! Init_li() let @l="I \ \+EB" nnoremap \£l ciW:exe 'norm a' . b:li_class . "> \evitholp2EB" vnoremap \l c:exe 'norm a' . b:li_class . "> \evitholgpvatov:s/\\s\\+$//ge\r=atvatv" endfunction call Init_ul () call Init_ol () call Init_p () call Init_div () call Init_td () call Init_a () call Init_span() call Init_h1 () call Init_i () call Init_em () call Init_b () call Init_li () " Set the class of a tag {{{2 " --------------------------- function! SetClass(tag, ...) if 'ul' == a:tag || 'u' == a:tag if !exists("a:1") let b:ul_class = '' else let b:ul_class = " class='" . a:1 . "'" endif call Init_ul() elseif 'ol' == a:tag || 'o' == a:tag if !exists("a:1") let b:ol_class = '' else let b:ol_class = " class='" . a:1 . "'" endif call Init_ol() elseif 'p' == a:tag if !exists("a:1") let b:p_class = '' else let b:p_class = " class='" . a:1 . "'" endif call Init_p() elseif 'div' == a:tag || 'd' == a:tag if !exists("a:1") let b:div_class = '' else let b:div_class = " class='" . a:1 . "'" endif call Init_div() elseif 'td' == a:tag || 't' == a:tag if !exists("a:1") let b:td_class = '' else let b:td_class = " class='" . a:1 . "'" endif call Init_td() elseif 'a' == a:tag if !exists("a:1") let b:a_class = '' else let b:a_class = " class='" . a:1 . "'" endif call Init_a() elseif 'span' == a:tag || 's' == a:tag if !exists("a:1") let b:span_class = '' else let b:span_class = " class='" . a:1 . "'" endif call Init_span() elseif 'h1' == a:tag || 'h' == a:tag if !exists("a:1") let b:h1_class = '' else let b:h1_class = " class='" . a:1 . "'" endif call Init_h1() elseif 'img' == a:tag || 'i' == a:tag if !exists("a:1") let b:i_class = '' else let b:i_class = " class='" . a:1 . "'" endif call Init_i() elseif 'em' == a:tag || 'e' == a:tag if !exists("a:1") let b:em_class = '' else let b:em_class = " class='" . a:1 . "'" endif call Init_i() elseif 'strong' == a:tag || 'b' == a:tag if !exists("a:1") let b:b_class = '' else let b:b_class = " class='" . a:1 . "'" endif call Init_b() elseif 'li' == a:tag || 'l' == a:tag if !exists("a:1") let b:li_class = '' else let b:li_class = " class='" . a:1 . "'" endif call Init_li() endif endfunction command! -complete=customlist,HtmlTags -nargs=+ Class :call SetClass() function! HtmlTags(A,L,P) return ['div ', 'span ', 'ul ', 'ol ', 'h1 ', 'li ', 'td ', 'img ', 'em ', 'strong ', 'a ', 'p '] endfunction " Close an opening tag {{{2 " ------------------------- " Each tag on a new line inoremap >> > 4hvi4l"*p`[3hrO " Both tags on the same line inoremap >/ >3hvi3l"*pcit inoremap " Wrap a line, a WORD or a selection with {{{2 " ----------------------------------------------------- let @c="I\+EB" nnoremap \£c ciWEB vnoremap \c cB2hvgpv?\?>v?\?>/s-1v?\?>=jgqqjoEB:noh nnoremap \r @='\£r' " Strip outer tags {{{2 " --------------------- let @x="vitdvatpgv:s/\\s\\+$//ge\gv=`>EB" nnoremap \£x ?\_.\=\?>/s-1v?\?>/epgv=`>EB:noh nnoremap \x @='\£x' " 'Space' content of a pair of tags {{{2 " -------------------------------------- let @m="vitgeowVc\\P-=at']+EB" nnoremap \£m ?\_.\=\?>O+v?