" mfuncs.vim " " Mapping related functions. " ********************************************************* let s:InsertTagTemplateKey = "" let s:InsertSymbolKey = "" let s:InsertForeignCharKey = "" let s:InsertStartTagKey = "" let s:InsertEndTagKey = "" let s:TagWordKey = "" let s:TagRangeKey = "" let s:ChangeTagKey = "" " ********************************************************* " Create mappings for: " - Inserting a tag template (start tag, end tag). " - Inserting a start tag. " - Inserting an end tag. " - Tagging a word with a start tag and end tag. " - Tagging a range of lines with a start tag and end tag. " - Change a tag. function! MapTagKey(key, snewline, enewline, tag, stagx) " Command/leadin text depends on whether or not the tag should be on a new line. let sicmd = a:snewline ? " " : " " let sncmd = a:snewline ? " o" : " a" let eicmd = a:enewline ? " " : " " let encmd = a:enewline ? " o" : " a" let ticmd = a:enewline ? "" : "" let cr = "" " Create tag text (check for special tags). if a:tag == "CDATA" let stag = "" elseif a:tag == "COMMENT" let stag = "" else let stag = "<" . a:tag . a:stagx . ">" let etag = "" endif " Map keys for template tag (check for predefined template string). if exists("g:Template_" . a:tag) let tmpl = g:Template_{a:tag} " Template string exists let icmd = "imap " . s:InsertTagTemplateKey . a:key . sicmd . tmpl . "\?-:-3xi" let ncmd = "nmap " . s:InsertTagTemplateKey . a:key . sncmd . tmpl . "\?-:-3xi" else let icmd = "imap " . s:InsertTagTemplateKey . a:key . sicmd . stag . ticmd . etag let ncmd = "nmap " . s:InsertTagTemplateKey . a:key . sncmd . stag . ticmd . etag " Reposition cursor between tags after insert. if strlen(ticmd) == 0 let i = 0 let n = strlen(etag) while i < n let icmd = icmd . "" let ncmd = ncmd . "" let i = i + 1 endwhile else let icmd = icmd . "" let ncmd = ncmd . "" endif endif execute icmd execute ncmd " Map keys for start tag. execute "imap " . s:InsertStartTagKey . a:key . sicmd . stag execute "nmap " . s:InsertStartTagKey . a:key . sncmd . stag " Map keys for end tag. execute "imap " . s:InsertEndTagKey . a:key . eicmd . etag execute "nmap " . s:InsertEndTagKey . a:key . encmd . etag let stag = escape(stag, "\"") let etag = escape(etag, "\"") " Map key for tagging a word. execute "nmap " . s:TagWordKey . a:key . " :call TagWord(\"" . stag . "\", \"" . etag "\")" . cr " Map key for tagging a range. execute "cmap " . s:TagRangeKey . a:key . " :call TagRange(\"" . stag . "\", \"" . etag "\")" . cr " Map key for changing tag. execute "nmap " . s:ChangeTagKey . a:key . " :call ChangeTag(\"" . stag . "\", \"" . etag "\")" . cr endfunction " ********************************************************* " Create mapping for symbol. function! MapSymbolKey(key, sym) execute "imap " . s:InsertSymbolKey . a:key . " " . a:sym execute "nmap " . s:InsertSymbolKey . a:key . " a" . a:sym endfunction " ********************************************************* " Create mapping for foreign characater. function! MapForeignCharKey(key, fchar) execute "imap " . s:InsertForeignCharKey . a:key . " " . a:fchar execute "nmap " . s:InsertForeignCharKey . a:key . " a" . a:fchar endfunction