Chinaunix首页 | 论坛 | 博客
  • 博客访问: 389117
  • 博文数量: 61
  • 博客积分: 2525
  • 博客等级: 少校
  • 技术积分: 455
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-24 13:22
文章分类

全部博文(61)

文章存档

2008年(4)

2007年(57)

我的朋友

分类:

2008-07-16 22:50:07

 因为需要在代码中配对if和end if,所有需要写个vim的脚本,来做这些,使得自己不会被很多的嵌套If所淹没...

 1 function Set_IfEnd_Syn()
 2     syn region If_End_Src start="@@@" end="@@@"
 3     hi If_End_Src guibg=SeaGreen
 4 endfun
 5
 6 function Del_mark()
 7     let s:cur_line=line(".")
 8     if g:IfEnd_Line1>0 || g:IfEnd_Line2>0
 9         exe "normal".g:IfEnd_Line1."G"
10         let s:tmpstr=getline(".")
11         if match(s:tmpstr,"@@@")>=0
12             exe "normal \3x"
13         endif
14         exe "normal".g:IfEnd_Line2."G"
15         let s:tmpstr=getline(".")
16         if match(s:tmpstr,"@@@")>=0
17             exe "normal \XXx"
18         endif
19         let g:IfEnd_Line1=0
20         let g:IfEnd_Line2=0
21     endif
22     exec "normal ".s:cur_line."G"
23 endfun
24
25 function Add_mark()
26     if g:IfEnd_Line1>0 && g:IfEnd_Line2>g:IfEnd_Line1
27         exec "normal ".g:IfEnd_Line2."G"
28         exec "normal \a@@@\"
29         exec "normal ".g:IfEnd_Line1."G"
30         exe "normal \i@@@\"
31     endif
32 endfun
33
34 function Search_End()
35     call Del_mark()
36     exec "normal 0"
37     exec "normal /^\\s*if\\>\"
38     let g:IfEnd_Line1=line(".")
39     let s:end_count=1
40     while s:end_count>0
41         exec "normal j"
42         let s:str=getline(".")
43         let s:result = match(s:str,"^\\s*if\\>")
44         if s:result >= 0
45             let s:end_count = s:end_count + 1
46         else
47             let s:result=match(s:str,"^\\s*end if\\>")
48             if s:result >=0
49                 let s:end_count = s:end_count - 1
50             endif
51         endif
52     endwhile
53
54     let g:IfEnd_Line2=line(".")
55     call Add_mark()
56 endfun
57
58 function Search_If()
59     call Del_mark()    
60     exec "normal 0"
61     exec "normal /\\\\>\"
62     let g:IfEnd_Line2=line(".")
63         let s:end_count=1
64         while s:end_count>0
65             exec "normal k"
66             let s:str=getline(".")
67             let s:result = match(s:str,"^\\s*end if\\>")
68             if s:result >= 0
69                 let s:end_count = s:end_count + 1
70             else
71                 let s:result=match(s:str,"^\\s*if\\>")
72                 if s:result >=0
73                     let s:end_count = s:end_count - 1
74                 endif
75             endif
76         endwhile
77
78     let g:IfEnd_Line2=line(".")
79     call Add_mark()    
80 endfun
81
82 map <F2> :call Search_End()<CR>
83 map <F3> :call Search_If()<CR>
84 au BufRead * :call Set_IfEnd_Syn()
85

阅读(3572) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~