我的vim配置文件
来源:互联网 发布:linux驱动模块编译 编辑:程序博客网 时间:2024/06/16 05:02
VIMb被我搞崩溃了,重新配了一遍,想死。
set gfn=Consolas:h12 "设置字体autocmd GUIEnter * simalt ~x "打开就全屏显示文件set nu! "显示行号colorscheme desertsyntax enablesyntax onsyn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1hi cFunction gui=NONE guifg=#B5A1FF"关闭菜单栏"set guioptions-=m "remove menu bar set guioptions-=T "remove toolbar set guioptions-=r "remove right-hand scroll bar set guioptions-=L "remove left-hand scroll bar"解决乱码set encoding=utf-8set fileencodings=utf-8,chinese,latin-1if has("win32")set fileencoding=chineseelseset fileencoding=utf-8endif"解决菜单乱码source $VIMRUNTIME/delmenu.vimsource $VIMRUNTIME/menu.vim"解决consle输出乱码language messages zh_CN.utf-8 set ai "设置自动缩进set cindent "设置使用 C/C++ 语言的自动缩进方式set shiftwidth=4 "设置自动缩进 2 个空格set sts=4 "即设置 softtabstop 为 4. 输入 tab 后就跳了 4 格set tabstop=4 "实际的 tab 即为 4 个空格, 而不是缺省的 8 个set expandtab "在输入 tab 后, vim 用恰当的空格来填充这个 tabsource $VIMRUNTIME/vimrc_example.vimsource $VIMRUNTIME/mswin.vimbehave mswinset diffexpr=MyDiff()function MyDiff() let opt = '-a --binary ' if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg2 = v:fname_new if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif let arg3 = v:fname_out if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif if $VIMRUNTIME =~ ' ' if &sh =~ '\<cmd' if empty(&shellxquote) let l:shxq_sav = '' set shellxquote& endif let cmd = '"' . $VIMRUNTIME . '\diff"' else let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"' endif else let cmd = $VIMRUNTIME . '\diff' endif silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 if exists('l:shxq_sav') let &shellxquote=l:shxq_sav endifendfunction" Vim script file vim600:fdm=marker:" FileType: XML" Author: Rene de Zwart <renez (at) lightcon.xs4all.nl> " Maintainer: Rene de Zwart <renez (at) lightcon.xs4all.nl>" Last Change: Date: 2009-11-12 " Version: Revision: 1.37" " Licence: This program is free software; you can redistribute it" and/or modify it under the terms of the GNU General Public" License. See http://www.gnu.org/copyleft/gpl.txt" Credits: Devin Weaver <vim (at) tritarget.com> et all" for the original code. Guo-Peng Wen for the self" install documentation code." Bart vam Deenen for makeElement function" Rene de Zwart" Observation - If you want to do something to a match pair most of the time" you must do first the close tag. Because doing first the open" tag could change the close tag position." NOTE with filetype index on de standard indent/html.vim interferes" with xml.vim. You can" 1) set filetype indent off in .vimrc" 2) echo "let b:did_indent = 1" > .vim/indent/html.vim" Only do this when not done yet for this bufferif exists("b:did_ftplugin") finishendiflet b:did_ftplugin = 1setlocal commentstring=<!--%s-->" XML: thanks to Johannes Zellner and Akbar Ibrahim" - case sensitive" - don't match empty tags <fred/>" - match <!--, --> style comments (but not --, --)" - match <!, > inlined dtd's. This is not perfect, as it" gets confused for example by" <!ENTITY gt ">">if exists("loaded_matchit") let b:match_ignorecase=0 let b:match_words = \ '<:>,' . \ '<\@<=!\[CDATA\[:]]>,'. \ '<\@<=!--:-->,'. \ '<\@<=?\k\+:?>,'. \ '<\@<=\([^ \t>/]\+\)\%(\s\+[^>]*\%([^/]>\|$\)\|>\|$\):<\@<=/\1>,'. \ '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'endif" Script rgular expresion used. Documents those nasty criters {{{1let s:NoSlashBeforeGt = '\(\/\)\@\<!>'" Don't check for quotes around attributes!!!let s:Attrib = '\(\(\s\|\n\)\+\([^>= \t]\+=[^>&]\+\)\(\s\|\n\)*\)'let s:OptAttrib = s:Attrib . '*'. s:NoSlashBeforeGtlet s:ReqAttrib = s:Attrib . '\+'. s:NoSlashBeforeGtlet s:OpenTag = '<[^!/?][^>]*' . s:OptAttriblet s:OpenOrCloseTag = '<[^!?][^>]*'. s:OptAttriblet s:CloseTag = '<\/[^>]*'. s:NoSlashBeforeGtlet s:SpaceInfront = '^\s*<'let s:EndofName = '\($\|\s\|>\)'" Buffer variables {{{1let b:emptyTags='^\(area\|base\|br\|col\|command\|embed\|hr\|img\|input\|keygen\|link\|meta\|param\|source\|track\|wbr\)$'let b:firstWasEndTag = 0let b:html_mode =((&filetype =~ 'x\?html') && !exists("g:xml_no_html"))let b:haveAtt = 0let b:lastTag = ""let b:lastAtt = ""let b:suffix = (exists('g:makeElementSuf') ? g:makeElementSuf : ';;')let b:xml_use_xhtml = 0if exists('g:xml_use_xhtml')let b:xml_use_xhtml = g:xml_use_xhtmlelseif &filetype == 'xhtml'let b:xml_use_xhtml = 1enlet b:undo_ftplugin = "setlocal cms< isk<" \ . "| unlet b:match_ignorecase b:match_words"" NewFileXML -> Inserts <?xml?> at top of new file. {{{1if !exists("*NewFileXML")function! NewFileXML( ) " Where is g:did_xhtmlcf_inits defined? if &filetype == 'xml' || \ (!exists ("g:did_xhtmlcf_inits") &&\ b:xml_use_xhtml &&\ (&filetype =~ 'x\?html')) if append (0, '<?xml version="1.0"?>') normal! G endif endifendfunctionendif" Callback -> Checks for tag callbacks and executes them. {{{1if !exists("*s:Callback")function! s:Callback( xml_tag, isHtml ) let text = 0 if a:isHtml == 1 && exists ("*HtmlAttribCallback") let text = HtmlAttribCallback (a:xml_tag) elseif exists ("*XmlAttribCallback") let text = XmlAttribCallback (a:xml_tag) endif if text != '0' execute "normal! i " . text ."\<Esc>l" endifendfunctionendif" SavePos() saves position in bufferwide variable {{{1fun! s:SavePos()retu 'call cursor('.line('.').','. col('.'). ')'endf" findOpenTag() {{{1fun! s:findOpenTag(flag)call search(s:OpenTag,a:flag)endf" findCloseTag() {{{1fun! s:findCloseTag(flag)call search(s:CloseTag,a:flag)endf" GetTagName() Gets the tagname from start position {{{1"Now lets go for the name part. The namepart are xmlnamechars which"is quite a big range. We assume that everything after '<' or '</' "until the first 'space', 'forward slash' or '>' ends de name part.if !exists('*s:GetTagName')fun! s:GetTagName(from) let l:end = match(getline('.'), s:EndofName,a:from) return strpart(getline('.'),a:from, l:end - a:from )endfen" hasAtt() Looks for attribute in open tag {{{1" expect cursor to be on <fun! s:hasAtt()"Check if this open tag has attributeslet l:line = line('.') | let l:col = col('.') if search(b:tagName . s:ReqAttrib,'W') > 0 if l:line == line('.') && l:col == (col('.')-1)let b:haveAtt = 1enenendf " TagUnderCursor() Is there a tag under the cursor? {{{1" Set bufer wide variable" - b:firstWasEndTag" - b:tagName" - b:endcol & b:endline only used by Match()" - b:gotoCloseTag (if the tag under the cursor is one)" - b:gotoOpenTag (if the tag under the cursor is one)" on exit" - returns 1 (true) or 0 (false)" - position is at '<'if !exists('*s:TagUnderCursor')fun! s:TagUnderCursor()let b:firstWasEndTag = 0let l:haveTag = 0let b:haveAtt = 0"Lets find forward a < or a >. If we first find a > we might be in a tag."If we find a < first or nothing we are definitly not in a tagif getline('.')[col('.') - 1] == '>'let b:endcol = col('.')let b:endline = line('.')if getline('.')[col('.')-2] == '/'"we don't work with empty tagsretu l:haveTagen " begin: gwang customization for JSP developmentif getline('.')[col('.')-2] == '%'"we don't work with jsp %> tagsretu l:haveTagen " end: gwang customization for JSP development " begin: gwang customization for PHP developmentif getline('.')[col('.')-2] == '?'"we don't work with php ?> tagsretu l:haveTagen " end: gwang customization for PHP developmentelseif search('[<>]','W') >0if getline('.')[col('.')-1] == '>'let b:endcol = col('.')let b:endline = line('.')if getline('.')[col('.')-2] == '-'"we don't work with comment tagsretu l:haveTagenif getline('.')[col('.')-2] == '/'"we don't work with empty tagsretu l:haveTagenelretu l:haveTagenelretu l:haveTagenif search('[<>]','bW' ) >=0if getline('.')[col('.')-1] == '<'if getline('.')[col('.')] == '/'let b:firstWasEndTag = 1let b:gotoCloseTag = s:SavePos()elseif getline('.')[col('.')] == '?' || getline('.')[col('.')] == '!'"we don't deal with processing instructions or dtd"related definitionsretu l:haveTagellet b:gotoOpenTag = s:SavePos()enelretu l:haveTagenelretu l:haveTagen"we have established that we are between something like"'</\?[^>]*>'let b:tagName = s:GetTagName(col('.') + b:firstWasEndTag)"echo 'Tag ' . b:tagName "begin: gwang customization, do not work with an empty tag name if b:tagName == '' retu l:haveTag en "end: gwang customization, do not work with an empty tag namelet l:haveTag = 1if b:firstWasEndTag == 0call s:hasAtt()exe b:gotoOpenTagenretu l:haveTagendfen " Match(tagname) Looks for open or close tag of tagname {{{1" Set buffer wide variable" - b:gotoCloseTag (if the Match tag is one)" - b:gotoOpenTag (if the Match tag is one)" on exit" - returns 1 (true) or 0 (false)" - position is at '<'if !exists('*s:Match')fun! s:Match(name)let l:pat = '</\=' . a:name . s:OptAttribif b:firstWasEndTagexe b:gotoCloseTaglet l:flags='bW'let l:level = -1elexe 'normal! '.b:endline.'G0'.(b:endcol-1).'l'let l:flags='W'let l:level = 1enwhile l:level && search(l:pat,l:flags) > 0let l:level = l:level + (getline('.')[col('.')] == '/' ? -1 : 1)endwhileif l:levelecho "no matching tag!!!!!"retu l:levelenif b:firstWasEndTaglet b:gotoOpenTag = s:SavePos()call s:hasAtt()exe b:gotoOpenTagellet b:gotoCloseTag = s:SavePos()enretu l:level == 0endfen" InComment() Is there a Comment under the cursor? {{{1" - returns 1 (true) or 0 (false)if !exists('*s:InComment')fun! s:InComment()let b:endcom=0let b:begcom=0"Lets find forward a < or a >. If we first find a > we might be in a comment."If we find a < first or nothing we are definitly not in a Commentif getline('.')[col('.') - 1] == '>'if getline('.')[col('.')-2] == '-' && getline('.')[col('.')-3] == '-'let b:endcomcol=col('.')let b:endcomline=line('.')let b:endcom=1retu 1enelseif getline('.')[col('.')-1] == '<' && getline('.')[col('.')] == '!' \ && getline('.')[col('.')+1] == '-' && getline('.')[col('.')+2] == '-' let b:begcomcol= col('.')let b:begcomline=line('.')let b:begcom=1retu 1en"We are not standing on a begin/end comment"Is the first > an ending comment?if search('[<>]','W') >0if getline('.')[col('.')-1] == '>'if getline('.')[col('.')-2] == '-' && getline('.')[col('.')-3] == '-'let b:endcomcol=col('.')let b:endcomline=line('.')let b:endcom=1retu 1enenen"Forward is not a ending comment"is backward a starting commentif search('[<>]','bW' ) >=0if getline('.')[col('.')-1] == '<' && getline('.')[col('.')] == '!' \ && getline('.')[col('.')+1] == '-' && getline('.')[col('.')+2] == '-' let b:begcomcol=col('.')let b:begcomline=line('.')let b:begcom=1retu 1enenretu 0endfen " DelComment() Is there a Comment under the cursor? {{{1" - returns 1 (true) or 0 (false)if !exists('*s:DelComment')fun! s:DelComment()let l:restore = s:SavePos()if s:InComment()if b:begcomif search('-->','W' ) >=0normal! hh3x call cursor(b:begcomline,b:begcomcol)normal! 4xretu 1enelif search('<!--','bW' ) >=0normal! 4x call cursor(b:endcomline,b:endcomcol)normal! hh3xretu 1enenenexe l:restoreretu 0endfen " DelCommentSection() Is there a Comment under the cursor? {{{1" - returns 1 (true) or 0 (false)if !exists('*s:DelCommentSection')fun! s:DelCommentSection()let l:restore = s:SavePos()if s:InComment()let l:sentinel = 'XmLSeNtInElXmL'let l:len = strlen(l:sentinel)if b:begcomif search('-->','W' ) >=0exe "normal! f>a".l:sentinel."\<Esc>" call cursor(b:begcomline,b:begcomcol)exe "normal! \"xd/".l:sentinel."/e-".l:len."\<Cr>"exe "normal! ".l:len."x"retu 1enelif search('<!--','bW' ) >=0let l:restore = s:SavePos() call cursor(b:endcomline,b:endcomcol)exe "normal! a".l:sentinel."\<Esc>"exe l:restoreexe "normal! \"xd/".l:sentinel."/e-".l:len."\<Cr>"exe "normal! ".l:len."x"retu 1enenenexe l:restoreretu 0endfen " DelCData() Is there a CData under the cursor? {{{1" - returns 1 (true) or 0 (false)if !exists('*s:DelCData')fun! s:DelCData()let l:restore = s:SavePos()if s:InCData()if b:begdatif search(']]>','W' ) >=0normal! hh3x call cursor(b:begdatline,b:begdatcol)normal! 9xretu 1enelif search('<![CDATA[','bW' ) >=0normal! 9x call cursor(b:enddatline,b:enddatcol)normal! hh3xretu 1enenenexe l:restoreretu 0endfen " InCData() Is there a CData under the cursor? {{{1" - returns 1 (true) or 0 (false)if !exists('*s:InCData')fun! s:InCData()let b:enddat=0let b:begdat=0"Lets find forward a < or a >. If we first find a > we might be in a comment."If we find a < first or nothing we are definitly not in a Commentif getline('.')[col('.') - 1] == '>'if getline('.')[col('.')-2] == ']' && getline('.')[col('.')-3] == ']'let b:enddatcol=col('.')let b:enddatline=line('.')let b:enddat=1retu 1enelseif getline('.')[col('.')-1] == '<' if match(getline('.'),'<![CDATA[') > 0let b:begdatcol= col('.')let b:begdatline=line('.')let b:begdat=1retu 1enen"We are not standing on a begin/end comment"Is the first > aending comment?if search('[<>]','W') >0if getline('.')[col('.')-1] == '>'if getline('.')[col('.')-2] == ']' && getline('.')[col('.')-3] == ']'let b:enddatcol=col('.')let b:enddatline=line('.')let b:enddat=1retu 1enenen"Forward is not a ending datment"is backward a starting commentif search('[<>]','bW' ) >=0if getline('.')[col('.')-1] == '<' if match(getline('.'),'<![CDATA[') > 0let l:newname = inputdialog('Found CDATA')let b:begdatcol=col('.')let b:begdatline=line('.')let b:begdat=1retu 1enenenretu 0endfen " DelCDataSection() Is there a CData under the cursor? {{{1" - returns 1 (true) or 0 (false)if !exists('*s:DelCDataSection')fun! s:DelCDataSection()let l:restore = s:SavePos()if s:InCData()let l:sentinel = 'XmLSeNtInElXmL'let l:len = strlen(l:sentinel)if b:begdatif search(']]>','W' ) >=0exe "normal! f>a".l:sentinel."\<Esc>" call cursor(b:begdatline,b:begdatcol)exe "normal! \"xd/".l:sentinel."/e-".l:len."\<Cr>"exe "normal! ".l:len."x"retu 1enelif search('<![CDATA[','bW' ) >=0let l:restore = s:SavePos() call cursor(b:enddatline,b:enddatcol)exe "normal! a".l:sentinel."\<Esc>"exe l:restoreexe "normal! \"xd/".l:sentinel."/e-".l:len."\<Cr>"exe "normal! ".l:len."x"retu 1enenenexe l:restoreretu 0endfen " Matches() Matches de tagname under de cursor {{{1if !exists('*s:Matches')fun! s:Matches()let l:restore = s:SavePos()if s:TagUnderCursor()if s:Match(b:tagName)retuenenexe l:restoreendfen" MatchesVisual() Matches de tagname under de cursor {{{1if !exists('*s:MatchesVisual')fun! s:MatchesVisual()let l:restore = s:SavePos()if s:TagUnderCursor()if b:firstWasEndTagnormal! f>ennormal! gvif s:Match(b:tagName)if b:firstWasEndTag == 0normal! f>en retuennormal! venexe l:restoreendfen" makeElement() makes the previous woord an tag and close {{{1if !exists('*s:makeElement')function! s:makeElement()let b:tagName = @@let b:haveAtt = 0let l:alone = (match(getline('.'),'^\s*>\s*$') >= 0)let l:endOfLine = ((col('.')+1) == col('$'))normal! i<pf>if b:html_mode && b:tagName =~? b:emptyTagsif b:haveAtt == 0call s:Callback (b:tagName, b:html_mode)endifif b:xml_use_xhtmlexe "normal! i/\<Esc>l"enif l:endOfLinestart!elnormal! lstartenelif b:haveAtt == 0call s:Callback (b:tagName, b:html_mode)endif l:aloneexe 'normal! o</pa>Ox>>$x'start!elexe 'normal! a</pa>F<'start enenendfunctionen" CloseTagFun() closing the tag which is being typed {{{1if !exists('*s:CloseTagFun')fun! s:CloseTagFun()let l:restore = s:SavePos()let l:endOfLine = ((col('.')+1) == col('$'))if col('.') > 1 && getline('.')[col('.')-2] == '>'"Multiline request. <t>></t> -->"<t>" cursor comes here"</t> normal! hif s:TagUnderCursor()if b:firstWasEndTag == 0 if exists('b:did_indent') && b:did_indent == 1 exe "normal! 2f>s\<Cr>\<Esc>Ox\<Esc>$x" else exe "normal! 2f>s\<Cr>\<Esc>Ox\<Esc>>>$x" enstart!retuenenelseif s:TagUnderCursor()if b:firstWasEndTag == 0exe "normal! />\<Cr>"if b:html_mode && b:tagName =~? b:emptyTagsif b:haveAtt == 0call s:Callback (b:tagName, b:html_mode)enif b:xml_use_xhtmlexe "normal! i/\<Esc>l"enif l:endOfLinestart!retuelnormal! lstartretuenelif b:haveAtt == 0call s:Callback (b:tagName, b:html_mode)enexe "normal! a</" . b:tagName . ">\<Esc>F<"startretuenenenexe l:restoreif (col('.')+1) == col("$")startinsert!elsenormal! lstartinsertenendfen" BlockTag() Surround a visual block with a tag {{{1" Be carefull where You place the block " the top is done with insert!" the bottem is done with append!if !exists('*s:BlockTag')fun! s:BlockTag(multi)let l:newname = inputdialog('Surround block with : ',b:lastTag)if strlen( l:newname) == 0retuenlet b:lastTag = l:newnamelet l:newatt = inputdialog('Attributes for '.l:newname.' : ',b:lastAtt)if strlen(l:newatt)let b:lastAtt = l:newatten"Get at the end of the blockif col('.') == col("'<") && line('.') == line("'<")normal! gvovenif a:multiexe "normal! a\<Cr></".l:newname.">\<Cr>\<Esc>"let l:eline = line('.')normal! gvovif col('.') == col("'>") && line('.') == line("'>")normal! gvovenlet l:sline = line(".") + 2exe "normal! i\<Cr><".l:newname.\ (strlen(l:newatt) ? ' '.l:newatt : '' )\ .">\<Cr>\<Esc>"let l:rep=&reportlet &report=999999exe l:sline.','.l:eline.'>'let &report= l:repexe 'normal! '.l:sline.'G0mh'.l:eline."G$v'hgq"elexe "normal! a</".l:newname.">\<Esc>gvov"if col('.') == col("'>") && line('.') == line("'>")normal! gvovenexe "normal! i<".l:newname.\ (strlen(l:newatt) ? ' '.l:newatt : '' )\ .">\<Esc>"enendfen" BlockWith() Surround a visual block with a open and a close {{{1" Be carefull where You place the block " the top is done with insert!" the bottem is done with append!if !exists('*s:BlockWith')fun! s:BlockWith(open,close)if col('.') == col("'<") && line('.') == line("'<")normal! gvovenexe "normal! a\<Cr>;x\<Esc>0cfx".a:close."\<Cr>\<Esc>"normal! gvovexe "normal! i\<Cr>;x\<Esc>0cfx".a:open."\<Cr>\<Esc>"endfen" vlistitem() Surround a visual block with a listitem para tag {{{1" Be carefull where You place the block " the top is done with insert!" the bottem is done with append!if !exists('*s:vlistitem')fun! s:vlistitem()"Get at the end of the blockif col('.') == col("'<") && line('.') == line("'<")normal! gvovenexe "normal! a</para>\<Cr></listitem>\<Esc>mh"normal! gvovexe "normal! i\<Cr><listitem>\<Cr>\<Tab><para>\<Esc>'h/listitem>/e+1\<Cr>"endfen" Change() Only renames the tag {{{1if !exists('*s:Change')fun! s:Change()let l:restore = s:SavePos()if s:TagUnderCursor()let l:newname = inputdialog('Change tag '.b:tagName.' to : ',b:lastTag) if strlen( l:newname) == 0retuenlet b:lastTag = l:newnameif s:Match(b:tagName)exe b:gotoCloseTagexe 'normal! 2lcw' . l:newname . "\<Esc>"exe b:gotoOpenTagexe 'normal! lcw' . l:newname . "\<Esc>"enenendfen" Join() Joins two the same tag adjacent sections {{{1if !exists('*s:Join')fun! s:Join()let l:restore = s:SavePos()if s:TagUnderCursor()let l:pat = '<[^?!]\S\+\($\| \|\t\|>\)'let l:flags='W'if b:firstWasEndTag == 0let l:flags='Wb'enif search(s:OpenOrCloseTag,l:flags) > 0let l:secondChar = getline('.')[col('.')]if l:secondChar == '/' && b:firstWasEndTag ||l:secondChar != '/' && !b:firstWasEndTagexe l:restoreretuenlet l:end = 0if l:secondChar == '/'let l:end = 1enlet l:name = s:GetTagName(col('.') + l:end)if l:name == b:tagNameif b:firstWasEndTaglet b:gotoOpenTag = s:SavePos()ellet b:gotoCloseTag = s:SavePos()enlet l:DeleteTag = "normal! d/>/e\<Cr>"exe b:gotoCloseTagexe l:DeleteTagexe b:gotoOpenTagexe l:DeleteTagenenenexe l:restoreendfen" ChangeWholeTag() removes attributes and rename tag {{{1if !exists('*s:ChangeWholeTag')fun! s:ChangeWholeTag()if s:TagUnderCursor()let l:newname = inputdialog('Change whole tag '.b:tagName.' to : ',b:lastTag)if strlen(l:newname) == 0retuenlet b:lastTag = l:newnamelet l:newatt = inputdialog('Attributes for '.l:newname.' : ',b:lastAtt)if strlen(l:newatt)let b:lastAtt = l:newattenif s:Match(b:tagName)exe b:gotoCloseTagexe "normal! 2lc/>\<Cr>".l:newname."\<Esc>"exe b:gotoOpenTagexe "normal! lc/>/\<Cr>".l:newname.\ (strlen(l:newatt) ? ' '.l:newatt : '' )\."\<Esc>"enenendfen" Delete() Removes a tag '<a id="a">blah</a>' --> 'blah' {{{1if !exists('*s:Delete')fun! s:Delete()let l:restore = s:SavePos()if s:TagUnderCursor()if s:Match(b:tagName)let l:DeleteTag = "normal! d/>/e\<Cr>"exe b:gotoCloseTagexe l:DeleteTagexe b:gotoOpenTagexe l:DeleteTagenelseexe l:restoreenendfen" DeleteSection() Deletes everything between start of open tag and end of {{{1" closing tagif !exists('*s:DeleteSection')fun! s:DeleteSection()let l:restore = s:SavePos()if s:TagUnderCursor()if s:Match(b:tagName)let l:sentinel = 'XmLSeNtInElXmL'let l:len = strlen(l:sentinel)let l:rep=&reportlet &report=999999exe b:gotoCloseTagexe "normal! />\<Cr>a".l:sentinel."\<Esc>"exe b:gotoOpenTagexe "normal! \"xd/".l:sentinel."/e-".l:len."\<Cr>"exe "normal! ".l:len."x"let &report= l:repenenendfen"" FoldTag() Fold the tag under the cursor {{{1if !exists('*s:FoldTag')fun! s:FoldTag()let l:restore = s:SavePos()if s:TagUnderCursor()let l:sline = line('.')if s:Match(b:tagName)if b:firstWasEndTagexe '.,'.l:sline.'fold'elexe l:sline.',.fold'enenelexe l:restoreenendfen" FoldTagAll() Fold all tags of under the cursor {{{1" If no tag under the cursor it asks for a tagif !exists('*s:FoldTagAll')fun! s:FoldTagAll()let l:restore = s:SavePos()if s:TagUnderCursor()let l:tname = b:tagNameellet l:tname = inputdialog('Which tag to fold : ',b:lastTag)if strlen(l:tname) == 0exe l:restoreretuenlet b:lastTag = l:tnameennormal! G$let l:flag='w'while search('<'.l:tname.s:OptAttrib,l:flag) > 0let l:flag='W'let l:sline = line('.')let l:level = 1while l:level && search('</\='.l:tname.s:OptAttrib,'W') > 0let l:level = l:level + (getline('.')[col('.')] == '/' ? -1 : 1)endwhileif l:level == 0exe l:sline.',.fold'ellet l:tmp = \ inputdialog("The tag ".l:tname."(".l:sline.") doesn't have a closetag")breakenendwhileexe l:restoreendfen" StartTag() provide the opening tag {{{1if !exists('*s:StartTag')fun! s:StartTag()let l:restore = s:SavePos()let l:level = 1if getline('.')[col('.')-1] == '<' if s:TagUnderCursor() if b:firstWasEndTag exe 'normal! i<'. b:tagName.">\<Esc>F<"retuel let l:level = l:level + 1 enen exe l:restoreenwhile l:level && search(s:OpenOrCloseTag ,'W') > 0 let l:level = l:level + (getline('.')[col('.')] == '/' ? -1 : 1)endwhileif l:level == 0 let l:Name = s:GetTagName(col('.') + 1) exe l:restore exe 'normal! i<'. l:Name.">\<Esc>"enexe l:restoreendfen" EndTag() search for open tag and produce endtaf {{{1if !exists('*s:EndTag')fun! s:EndTag()let l:restore = s:SavePos()let l:level = -1while l:level && search(s:OpenOrCloseTag,'bW') > 0let l:level = l:level + (getline('.')[col('.')] == '/' ? -1 : 1)endwhileif l:level == 0 let l:Name = s:GetTagName(col('.')) exe l:restore exe 'normal! a</'. l:Name.">\e"el exe l:restoreenendfen" BeforeTag() surrounds the current tag with a new one {{{1if !exists('*s:BeforeTag')fun! s:BeforeTag()let l:restore = s:SavePos()if s:TagUnderCursor()let l:newname =\ inputdialog('Surround Before Tag '.b:tagName.' with : ',b:lastTag)if strlen(l:newname) == 0retuenlet b:lastTag = l:newnamelet l:newatt = inputdialog('Attributes for '.l:newname.' : ',b:lastAtt)if strlen(l:newatt)let b:lastAtt = l:newattenif s:Match(b:tagName)exe b:gotoCloseTagexe "normal! />\<Cr>a\<Cr></" . l:newname . ">\<Esc>"let l:To = line('.')exe b:gotoOpenTagexe 'normal! i<' . l:newname . \ (strlen(l:newatt) ? ' '.l:newatt : '' )\.">\<Cr>\<Esc>"let l:rep=&reportlet &report=999999exe line('.').','.l:To.'>'let &report= l:repenexe l:restoreenendfen" CommentTag() surrounds the current tag with a new one {{{1if !exists('*s:CommentTag')fun! s:CommentTag()let l:restore = s:SavePos()if s:TagUnderCursor()if s:Match(b:tagName)exe b:gotoCloseTagexe "normal! />\<Cr>a\<Cr>-->\<Esc>"let l:To = line('.')exe b:gotoOpenTagexe "normal! i<!--\<Cr>\<Esc>"let l:rep=&reportlet &report=999999exe line('.').','.l:To.'>'let &report= l:repenelseexe l:restoreenendfen" AfterTag() surrounds the tags after the current one with new {{{1if !exists('*s:AfterTag')fun! s:AfterTag()let l:restore = s:SavePos()if s:TagUnderCursor()let l:newname =\ inputdialog('Add Tag After '.b:tagName.' with : ',b:lastTag)if strlen(l:newname) == 0retuenlet b:lastTag = l:newnamelet l:newatt = inputdialog('Attributes for '.l:newname.' : ',b:lastAtt)if strlen(l:newatt)let b:lastAtt = l:newattenif s:Match(b:tagName)exe b:gotoCloseTagexe 'normal! i</' . l:newname . ">\<Cr>\<Esc>"let l:To = line('.')exe b:gotoOpenTagexe "normal! />\<Cr>a\<Cr><".l:newname.\ (strlen(l:newatt) ? ' '.l:newatt : '' )\.">\<Esc>"let l:rep=&reportlet &report=999999exe line('.').','.l:To.'>'let &report= l:repenenexe l:restoreendfen" ShiftRight() Shift the tag to the right {{{1if !exists('*s:ShiftRight')fun! s:ShiftRight()let l:restore = s:SavePos()if s:TagUnderCursor()let l:sline = line('.')if s:Match(b:tagName)let l:eline = line('.')if b:firstWasEndTagexe l:eline.','.l:sline.'>'elexe l:sline.','.l:eline.'>'enenenendfen" ShiftLeft() Shift the tag to the left {{{1if !exists('*s:ShiftLeft')fun! s:ShiftLeft()let l:restore = s:SavePos()if s:TagUnderCursor()let l:sline = line('.')if s:Match(b:tagName)let l:eline = line('.')if b:firstWasEndTagexe l:eline.','.l:sline.'<'elexe l:sline.','.l:eline.'<'enenenendfen" FormatTag() visual select the block and use gq {{{1if !exists('*s:FormatTag')fun! s:FormatTag()if s:TagUnderCursor()if s:Match(b:tagName)exe b:gotoCloseTagnormal! hhmhexe b:gotoOpenTagexe "normal! />/e+1\<Cr>v'hgq"enenendfen" FormatTagAll() Format all tags of name under the cursor {{{1" If no tag under the cursor it asks for a tagif !exists('*s:FormatTagAll')fun! s:FormatTagAll()let l:restore = s:SavePos()if s:TagUnderCursor()let l:tname = b:tagNameellet l:tname = inputdialog('Format every tag : ')if strlen(l:tname) == 0exe l:restoreretuenennormal! G$let l:flag = 'w'while search('<'.l:tname . s:OptAttrib, l:flag) > 0let l:flag = 'W'let l:sline = line('.')let l:level = 1exe "normal! />/e+1\<cr>mh"while l:level && search('</\='.l:tname . s:EndofName,'W') > 0let l:level = l:level + (getline('.')[col('.')] == '/' ? -1 : 1)endwhileif l:level == 0normal! hv'hogqellet l:tmp = \ inputdialog("The tag ".l:tname."(".l:sline.") doesn't have a closetag")breakenendwhileexe l:restoreendfen" IndentAll() indent all tags multiline {{{1if !exists('*s:IndentAll')fun! s:IndentAll()let l:restore = s:SavePos()let l:rep=&reportlet &report=999999"shift everything leftnormal! 1G<G<G<G<G<G<GG$if search(s:OpenTag,'w') > 0let l:level = 1normal! f>"if there is something after the tag move that to the next lineif col('.')+1 != col('$')echo "after tag".line('.')exe "normal! a\<Cr>\<Esc>"elnormal! jennormal! >Gk$while search(s:OpenOrCloseTag,'W') > 0"if there is text before the tag then move the tag to the next lineif match(getline('.'),s:SpaceInfront) == -1exe "normal! i\<Cr>\<Esc>l"enif getline('.')[col('.')] == '/'normal! <G0f>"if there is something after the tag move that to the next lineif col('.')+1 != col('$')exe "normal! a\<Cr>\<Esc>"enlet l:level = l:level - 1elnormal! f>"if there is something after the tag move that to the next lineif col('.')+1 != col('$')exe "normal! a\<Cr>\<Esc>"elnormal! j0ennormal! >Gk$let l:level = l:level + 1enendwhileif l:level let l:tmp = \ inputdialog("The tags opening and closing are unbalanced ".l:level)enenexe l:restorelet &report= l:rependfen" Menu options: {{{1augroup XML_menu_autosau!autocmd BufLeave,BufWinLeave * \ if &filetype == "xml" || &filetype == "html" || &filetype == "xhtml" | \ amenu disable Xml | \ amenu disable Xml.* | \ endifautocmd BufEnter,BufWinEnter * \ if &filetype == "xml" || &filetype == "html" || &filetype == "xhtml" | \ amenu enable Xml | \ amenu enable Xml.* | \ endifau BufNewFile * \ if &filetype == "xml" || &filetype == "html" || &filetype == "xhtml" | \ call NewFileXML() | \ endifaugroup ENDif !exists("g:did_xml_menu")let g:did_xml_menu = 1:1011 vmenu <script> &Xml.BlockTag\ multi<Tab>V <Esc>:call <SID>BlockTag(1)<Cr>vmenu <script> Xml.BlockTag\ inline<Tab>v <Esc>:call <SID>BlockTag(0)<CR>vmenu <script> Xml.Insert\ listitem<Tab>l <Esc>:call <SID>vlistitem()<CR>vmenu <script> Xml.Comment<Tab>< <Esc>:call <SID>BlockWith('<!--','-->')<Cr>vmenu <script> Xml.Comment\ With\ CData<Tab>c <Esc>:call <SID>BlockWith('<![CDATA[',']]>')<Cr>nmenu <script> Xml.Comment\ Tag<Tab>= <Esc>:call <SID>CommentTag()<Cr>imenu <script> Xml.Comment\ Tag<Tab>= <Esc>:call <SID>CommentTag()<Cr>nmenu <script> Xml.Change<Tab>c :call <SID>Change()<CR>imenu <script> Xml.Change<Tab>c <C-C>:call <SID>Change()<CR>nmenu <script> Xml.Change\ Whole\ Tag<Tab>C :call <SID>ChangeWholeTag()<CR>imenu <script> Xml.Change\ Whole\ Tag<Tab>C <C-C>:call <SID>ChangeWholeTag()<CR>nmenu <script> Xml.Delete\ Comment<Tab>] :call <SID>DelComment()<CR>imenu <script> Xml.Delete\ Comment<Tab>] <C-C>:call <SID>DelComment()<CR>nmenu <script> Xml.Delete\ Comment\ Section<Tab>} :call <SID>DelCommentSection()<CR>imenu <script> Xml.Delete\ Comment\ Section<Tab>} <C-C>:call <SID>DelCommentSection()<CR>nmenu <script> Xml.Delete\ CData<Tab>[ :call <SID>DelCData()<CR>imenu <script> Xml.Delete\ CData<Tab>[ <C-C>:call <SID>DelCData()<CR>nmenu <script> Xml.Delete\ CData\ Section<Tab>[ :call <SID>DelCDataSection()<CR>imenu <script> Xml.Delete\ CData\ Section<Tab>[ <C-C>:call <SID>DelCDataSection()<CR>nmenu <script> Xml.Delete\ Tag<Tab>d :call <SID>Delete()<CR>imenu <script> Xml.Delete\ Tag<Tab>d <C-C>:call <SID>Delete()<CR>nmenu <script> Xml.Delete\ Section<Tab>D :call <SID>DeleteSection()<CR>imenu <script> Xml.Delete\ Section<Tab>D <C-C>:call <SID>DeleteSection()<CR>nmenu <script> Xml.End\ Tag<Tab>e :call <SID>EndTag()<CR>imenu <script> Xml.End\ Tag<Tab>e <C-C>:call <SID>EndTag()<CR>nmenu <script> Xml.Fold\ Comment :?<!--?,/-->/fo<CR>nmenu <script> Xml.Fold\ CData :?<!\[CDATA\[?,/\]\]>/fo<CR>nmenu <script> Xml.Fold\ Processing\ instruc :?<\?[a-zA-Z]*?,/?>/fo<CR>nmenu <script> Xml.Fold\ Tag<Tab>f :call <SID>FoldTag()<CR>nmenu <script> Xml.Fold\ All\ Tags<Tab>F :call <SID>FoldTagAll()<CR>nmenu <script> Xml.Format\ Tags<Tab>g :call <SID>FormatTag()<CR>nmenu <script> Xml.Format\ All\ Tags<Tab>G :call <SID>FormatTagAll()<CR>nmenu <script> Xml.Join<Tab>j :call <SID>Join()<CR>imenu <script> Xml.Join<Tab>j <C-C>:call <SID>Join()<CR>nmenu <script> Xml.Open\ After\ Tag<Tab>O :call <SID>AfterTag()<CR>imenu <script> Xml.Open\ After\ Tag<Tab>O <C-C>:call <SID>AfterTag()<CR>nmenu <script> Xml.open\ Before\ Tag<Tab>o :call <SID>BeforeTag()<CR>imenu <script> Xml.open\ Before\ Tag<Tab>o <C-C>:call <SID>BeforeTag()<CR>nmenu <script> Xml.Match<Tab>5 :call <SID>Matches()<CR>imenu <script> Xml.Match<Tab>5 <C-C>:call <SID>Matches()<CR><C-\><C-G>nmenu <script> Xml.Shift\ Left<Tab>< :call <SID>ShiftLeft()<CR>imenu <script> Xml.Shift\ Left<Tab>< <C-C>:call <SID>ShiftLeft()<CR><C-\><C-G>nmenu <script> Xml.Shift\ Right<Tab>> :call <SID>ShiftRight()<CR>imenu <script> Xml.Shift\ Right<Tab>> <C-C>:call <SID>ShiftRight()<CR><C-\><C-G>nmenu <script> Xml.Start\ Tag<Tab>s :call <SID>StartTag()<CR>imenu <script> Xml.Start\ Tag<Tab>s <C-C>:call <SID>StartTag()<CR><C-\><C-G>en" Section: Doc installation {{{1" Function: s:XmlInstallDocumentation(full_name, revision) {{{2" Install help documentation." Arguments:" full_name: Full name of this vim plugin script, including path name." revision: Revision of the vim script. #version# mark in the document file" will be replaced with this string with 'v' prefix." Return:" 1 if new document installed, 0 otherwise." Note: Cleaned and generalized by guo-peng Wen"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''function! s:XmlInstallDocumentation(full_name, revision) " Name of the document path based on the system we use: if (has("unix")) " On UNIX like system, using forward slash: let l:slash_char = '/' let l:mkdir_cmd = ':silent !mkdir -p ' else " On M$ system, use backslash. Also mkdir syntax is different. " This should only work on W2K and up. let l:slash_char = '\' let l:mkdir_cmd = ':silent !mkdir ' endif let l:doc_path = l:slash_char . 'doc' "let l:doc_home = l:slash_char . '.vim' . l:slash_char . 'doc' " Figure out document path based on full name of this script: let l:vim_plugin_path = fnamemodify(a:full_name, ':h') "let l:vim_doc_path = fnamemodify(a:full_name, ':h:h') . l:doc_path let l:vim_doc_path = matchstr(l:vim_plugin_path, \ '.\{-}\ze\%(\%(ft\)\=plugin\|macros\)') . l:doc_path if (!(filewritable(l:vim_doc_path) == 2)) echomsg "Doc path: " . l:vim_doc_path execute l:mkdir_cmd . l:vim_doc_path if (!(filewritable(l:vim_doc_path) == 2)) " Try a default configuration in user home: "let l:vim_doc_path = expand("~") . l:doc_home let l:vim_doc_path = matchstr(&rtp, \ escape($HOME, ' \') .'[/\\]\%(\.vim\|vimfiles\)') if (!(filewritable(l:vim_doc_path) == 2)) execute l:mkdir_cmd . l:vim_doc_path if (!(filewritable(l:vim_doc_path) == 2)) " Put a warning: echomsg "Unable to open documentation directory" echomsg " type :help add-local-help for more informations." return 0 endif endif endif endif " Exit if we have problem to access the document directory: if (!isdirectory(l:vim_plugin_path) \ || !isdirectory(l:vim_doc_path) \ || filewritable(l:vim_doc_path) != 2) return 0 endif " Full name of script and documentation file: let l:script_name = 'xml.vim' let l:doc_name = 'xml-plugin.txt' let l:plugin_file = l:vim_plugin_path . l:slash_char . l:script_name let l:doc_file = l:vim_doc_path . l:slash_char . l:doc_name " Bail out if document file is still up to date: if (filereadable(l:doc_file) && \ getftime(l:plugin_file) < getftime(l:doc_file)) return 0 endif " Prepare window position restoring command: if (strlen(@%)) let l:go_back = 'b ' . bufnr("%") else let l:go_back = 'enew!' endif " Create a new buffer & read in the plugin file (me): setl nomodeline exe 'enew!' exe 'r ' . l:plugin_file setl modeline let l:buf = bufnr("%") setl noswapfile modifiable norm zR norm gg " Delete from first line to a line starts with " === START_DOC 1,/^=\{3,}\s\+START_DOC\C/ d " Delete from a line starts with " === END_DOC " to the end of the documents: /^=\{3,}\s\+END_DOC\C/,$ d " Remove fold marks: "% s/{\{3}[1-9]/ / " Add modeline for help doc: the modeline string is mangled intentionally " to avoid it be recognized by VIM: call append(line('$'), '') call append(line('$'), ' v' . 'im:tw=78:ts=8:fen:fdm=marker:ft=help:norl:') " Replace revision: exe "normal! :1,5s/#version#/ v" . a:revision . "/\<CR>" " Save the help document: exe 'w! ' . l:doc_file exe l:go_back exe 'bw ' . l:buf " Build help tags: exe 'helptags ' . l:vim_doc_path return 1endfunction" }}}2let s:revision= \ substitute("$Revision: 1.36 $",'\$\S*: \([.0-9]\+\) \$','\1','')silent! let s:install_status = \ s:XmlInstallDocumentation(expand('<sfile>:p'), s:revision)if (s:install_status == 1) echom expand("<sfile>:t:r") . '-plugin v' . s:revision . \ ': Help-documentation installed.'endif" Mappings of keys to functions {{{1nnoremap <silent> <buffer> <LocalLeader>5 :call <SID>Matches()<Cr>vnoremap <silent> <buffer> <LocalLeader>5 <Esc>:call <SID>MatchesVisual()<Cr>nnoremap <silent> <buffer> <LocalLeader>% :call <SID>Matches()<Cr>vnoremap <silent> <buffer> <LocalLeader>% <Esc>:call <SID>MatchesVisual()<Cr>nnoremap <silent> <buffer> <LocalLeader>c :call <SID>Change()<Cr>nnoremap <silent> <buffer> <LocalLeader>C :call <SID>ChangeWholeTag()<Cr>nnoremap <silent> <buffer> <LocalLeader>d :call <SID>Delete()<Cr>nnoremap <silent> <buffer> <LocalLeader>D :call <SID>DeleteSection()<Cr>nnoremap <silent> <buffer> <LocalLeader>e :call <SID>EndTag()<Cr>nnoremap <silent> <buffer> <LocalLeader>] :call <SID>DelComment()<Cr>nnoremap <silent> <buffer> <LocalLeader>} :call <SID>DelCommentSection()<Cr>nnoremap <silent> <buffer> <LocalLeader>f :call <SID>FoldTag()<Cr>nnoremap <silent> <buffer> <LocalLeader>F :call <SID>FoldTagAll()<Cr>nnoremap <silent> <buffer> <LocalLeader>g :call <SID>FormatTag()<Cr>nnoremap <silent> <buffer> <LocalLeader>G :call <SID>FormatTagAll()<Cr>nnoremap <silent> <buffer> <LocalLeader>I :call <SID>IndentAll()<Cr>nnoremap <silent> <buffer> <LocalLeader>j :call <SID>Join()<Cr>nnoremap <silent> <buffer> <LocalLeader>O :call <SID>BeforeTag()<Cr>nnoremap <silent> <buffer> <LocalLeader>= :call <SID>CommentTag()<Cr>nnoremap <silent> <buffer> <LocalLeader>o :call <SID>AfterTag()<Cr>nnoremap <silent> <buffer> <LocalLeader>s :call <SID>StartTag()<Cr>nnoremap <silent> <buffer> <LocalLeader>[ :call <SID>DelCData()<Cr>nnoremap <silent> <buffer> <LocalLeader>{ :call <SID>DelCDataSection()<Cr>nnoremap <silent> <buffer> <LocalLeader>> :call <SID>ShiftRight()<Cr>nnoremap <silent> <buffer> <LocalLeader>< :call <SID>ShiftLeft()<Cr>vnoremap <silent> <buffer> <LocalLeader>l <Esc>:call <SID>vlistitem()<Cr>vnoremap <silent> <buffer> <LocalLeader>v <Esc>:call <SID>BlockTag(0)<Cr>vnoremap <silent> <buffer> <LocalLeader>V <Esc>:call <SID>BlockTag(1)<Cr>vnoremap <silent> <buffer> <LocalLeader>c <Esc>:call <SID>BlockWith('<![CDATA[',']]>')<Cr>vnoremap <silent> <buffer> <LocalLeader>< <Esc>:call <SID>BlockWith('<!--','-->')<Cr>" Move around functions.noremap <silent><buffer> [[ m':call <SID>findOpenTag("bW")<CR>noremap <silent><buffer> ]] m':call <SID>findOpenTag( "W")<CR>noremap <silent><buffer> [] m':call <SID>findCloseTag( "bW")<CR>noremap <silent><buffer> ][ m':call <SID>findCloseTag( "W")<CR>" Move around commentsnoremap <silent><buffer> ]" :call search('^\(\s*<!--.*\n\)\@<!\(\s*-->\)', "W")<CR>noremap <silent><buffer> [" :call search('\%(^\s*<!--.*\n\)\%(^\s*-->\)\@!', "bW")<CR>setlocal iskeyword=@,48-57,_,192-255,58 exe 'inoremap <silent> <buffer> '.b:suffix. " ><Esc>db:call <SID>makeElement()<Cr>"if !exists("g:xml_tag_completion_map") inoremap <silent> <buffer> > ><Esc>:call <SID>CloseTagFun()<Cr>else execute "inoremap <silent> <buffer> " . g:xml_tag_completion_map . " ><Esc>:call <SID>CloseTagFun()<Cr>"endiffinish
阅读全文
0 0
- 我的VIM配置文件
- 我的VIM配置文件
- 我的vim配置文件
- 我的VIM配置文件
- 我的vim配置文件
- 我的VIM配置文件
- 我的vim配置文件
- 我的vim配置文件
- 我的vim配置文件
- 我的VIM配置文件
- 我的vim配置文件
- 我的vim配置文件
- 我的vim配置文件
- 我的vim配置文件
- 我的vim配置文件
- 我的vim配置文件
- 我的vim配置文件
- 我的VIM的配置文件
- PAT 1011::World Cup Betting (20)
- C++常用函数
- Java基础教程1-Java特点和手把手教你安装JDK
- USACO-Section1.3 Combination Lock
- Python数据分析-小技巧[1]
- 我的vim配置文件
- webmagic 0.70学习
- Linux系统下解压缩*.tar.xz方法
- TCP的超时与重传
- Android多线程和异步消息的简单应用
- lua语言中的函数概念
- c语言数据结构
- Detours express3.0在VS2013中编译生产库
- Vue.js 学习3 模板