-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthorinfo.vim
More file actions
196 lines (187 loc) · 5.61 KB
/
authorinfo.vim
File metadata and controls
196 lines (187 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
"=============================================================================
" Author: dantezhu - http://www.vimer.cn
" Email: zny2008@gmail.com
" FileName: authorinfo.vim
" Description:
" Version: 1.5
" LastChange: 2011-02-23 16:42:42
" History: support bash's #!xxx
" fix bug for NerdComment's <leader>
"=============================================================================
if exists('g:loaded_authorinfo')
finish
endif
let g:loaded_authorinfo= 1
if exists("mapleader")
let s:t_mapleader = mapleader
elseif exists("g:mapleader")
let s:t_mapleader = g:mapleader
else
let s:t_mapleader = '\'
endif
function! g:CheckFileType(type)
let t_filetypes = split(&filetype,'\.')
if index(t_filetypes,a:type)>=0
return 1
else
return 0
endif
endfunction
function s:DetectFirstLine()
"跳转到指定区域的第一行,开始操作
exe 'normal '.1.'G'
let arrData = [
\['sh',['^#!.*$']],
\['python',['^#!.*$','^#.*coding:.*$']],
\['php',['^<?.*']]
\]
let oldNum = line('.')
while 1
let line = getline('.')
let findMatch = 0
for [t,v] in arrData
if g:CheckFileType(t)
for it in v
if line =~ it
let findMatch = 1
break
endif
endfor
endif
endfor
if findMatch != 1
break
endif
normal j
"到了最后一行了,所以直接o就可以了
if oldNum == line('.')
normal o
return
endif
let oldNum = line('.')
endwhile
normal O
endfunction
function s:BeforeTitle()
let arrData = [['python',"'''"]]
for [t,v] in arrData
if g:CheckFileType(t)
call setline('.',v)
normal o
break
endif
endfor
endfunction
function s:AfterTitle()
let arrData = [['python',"'''"]]
for [t,v] in arrData
if g:CheckFileType(t)
normal o
call setline('.',v)
normal k
break
endif
endfor
endfunction
function s:AddTitle()
"检查开始插入作者信息的行
call s:DetectFirstLine()
"判断是否支持多行注释
let hasMul = 0
let preChar = ''
let noTypeChar = ''
call setline('.','test mul')
let oldline = getline('.')
exec 'normal '.s:t_mapleader.'cm'
let newline = getline('.')
if oldline != newline
let hasMul = 1
"let preChar = '#'
let preChar = '*'
else
exec 'normal '.s:t_mapleader.'cl'
let newline = getline('.')
if oldline == newline
let hasMul = -1
let noTypeChar = '#'
endif
endif
"在第一行之前做的事情
call s:BeforeTitle()
"let firstLine = line('.')
"call setline('.',noTypeChar.'=============================================================================')
"normal o
"call setline('.',noTypeChar.preChar.' FileName: '.expand("%:t"))
"normal o
"call setline('.',noTypeChar.preChar.' Desc: ')
"let gotoLn = line('.')
"normal o
"call setline('.',noTypeChar.preChar.' Author: '.g:vimrc_author)
"normal o
"call setline('.',noTypeChar.preChar.' Email: '.g:vimrc_email)
"normal o
"call setline('.',noTypeChar.preChar.' HomePage: '.g:vimrc_homepage)
"normal o
"call setline('.',noTypeChar.preChar.' Version: 0.0.1')
"normal o
"call setline('.',noTypeChar.preChar.' LastChange: '.strftime("%Y-%m-%d %H:%M:%S"))
"normal o
"call setline('.',noTypeChar.preChar.' History:')
"normal o
"call setline('.',noTypeChar.'=============================================================================')
"let lastLine = line('.')
let firstLine = line('.')
call setline('.',noTypeChar.'*')
normal o
call setline('.',noTypeChar.preChar.' @file '.expand("%:t"))
normal o
call setline('.',noTypeChar.preChar.' @detail ')
let gotoLn = line('.')
normal o
call setline('.',noTypeChar.preChar.' @author '.g:vimrc_author)
normal o
call setline('.',noTypeChar.preChar.' @email '.g:vimrc_email)
normal o
call setline('.',noTypeChar.preChar.' @version 0.0.1')
normal o
call setline('.',noTypeChar.preChar.' @date '.strftime("%Y-%m-%d %H:%M:%S"))
normal o
let lastLine = line('.')
"在最后一行之后做的事情
call s:AfterTitle()
if hasMul == 1
exe 'normal '.firstLine.'Gv'.lastLine.'G'.s:t_mapleader.'cm'
else
exe 'normal '.firstLine.'Gv'.lastLine.'G'.s:t_mapleader.'cl'
endif
exe 'normal '.gotoLn.'G'
startinsert!
echohl WarningMsg | echo "Succ to add the copyright." | echohl None
endf
function s:TitleDet()
silent! normal ms
let updated = 0
let n = 1
"默认为添加
while n < 20
let line = getline(n)
if line =~ '^.*FileName:\S*.*$'
let newline=substitute(line,':\(\s*\)\(\S.*$\)$',':\1'.expand("%:t"),'g')
call setline(n,newline)
let updated = 1
endif
if line =~ '^.*LastChange:\S*.*$'
let newline=substitute(line,':\(\s*\)\(\S.*$\)$',':\1'.strftime("%Y-%m-%d %H:%M:%S"),'g')
call setline(n,newline)
let updated = 1
endif
let n = n + 1
endwhile
if updated == 1
silent! normal 's
echohl WarningMsg | echo "Succ to update the copyright." | echohl None
return
endif
call s:AddTitle()
endfunction
command! -nargs=0 AuthorInfoDetect :call s:TitleDet()