将光标移动到Func上, 执行 MakeRegionPair() 脚本便可生成. shell
#region 生成在当前行上面的第一个空行处.code
#endregion 生成在与开始的 '{' 匹配的 '}' 处, 注意 '{' 必须是单独一行.orm
生成结果:get
代码:io
function! GetHeadSpace() normal ^ let colPos = col(".") if ( colPos > 1 ) normal hv0 normal "ay return @a endif return "" endfunction function! MakeRegionPair() let empty_pattern = "^\\s*$" let brace_pattern = "^\\s*{\\s*$" normal viwy let text = getreg("@*") let headSpace = GetHeadSpace() let regiontext = "\n" . headSpace . "#region " . text let endregiontext = headSpace . "#endregion //" . text . "\n" normal mm let curr_line = line(".") let line_b = FindLine( curr_line, 0, empty_pattern ) execute "normal " . line_b . "G" call setreg('c', regiontext) normal "cP normal 'm let line_e = FindLine(curr_line, 1, brace_pattern ) execute "normal " . line_e . "G" normal % call setreg('c', endregiontext) normal "cp endfunction " " dir 0 - up, 1 - down " function! FindLine( baseLine, dir, pattern ) let maxLine = line("$") if (a:dir == 0 ) let step = -1 let result = 1 else let step = 1 let result = maxLine endif let i = a:baseLine let i = i + step while 1 let theLine = getline(i) let mr = match( theLine, a:pattern) if ( mr != -1 ) let result = i break else let i = i + step endif if i<= 0 || i > maxLine break endif endwhile return result endfunction