-
编辑vim /etc/vimrc,如果针对用户,可修改用户家目录下的.vimrc文件
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
|
" 使用F4键调用函数AddAuthor
map <F4> ms:call AddAuthor()<cr>'S
function
AddAuthor()
let
n=1
while
n < 11
let
line = getline(n)
if
line=~
'[#]*\s*\*\s*\S*Last\s*modified\s*:\s*\S*.*$'
call UpdateTitle()
return
endif
let
n = n + 1
endwhile
if
&filetype ==
'sh'
call AddTitleForShell()
elseif &filetype ==
'python'
call AddTitleForPython()
else
call AddTitleForC()
endif
endfunction
""
表示非.sh或.py结尾的文件添加此函数注释
function
AddTitleForC()
call append(0,
"# **********************************************************"
)
call append(1,
""
)
call append(2,
"# * Create time : "
.strftime(
"%Y-%m-%d %H:%M"
))
call append(3,
"# * Filename : "
.
expand
(
"%:t"
))
call append(4,
""
)
call append(5,
"# **********************************************************"
)
endfunction
""
表示.py添加此函数注释
function
AddTitleForPython()
call append(0,
"#!/usr/bin/env python"
)
call append(1,
"# coding:utf-8"
)
call append(2,
""
)
call append(3,
"# **********************************************************"
)
call append(4,
"# * Author : pengyongshi"
)
call append(5,
"# * Email : 58217892@qq.com"
)
call append(6,
"# * Create time : "
.strftime(
"%Y-%m-%d %H:%M"
))
call append(7,
"# * Last modified : "
.strftime(
"%Y-%m-%d %H:%M"
))
call append(8,
"# * Filename : "
.
expand
(
"%:t"
))
call append(9,
"# * Description : "
)
call append(10,
"# **********************************************************"
)
echohl WarningMsg |
echo
"Successful in adding the copyright."
| echohl None
endfunction
""
表示.sh文件添加此行数注释
function
AddTitleForShell()
call append(0,
"#!/bin/bash"
)
call append(1,
"# **********************************************************"
)
call append(2,
"# * Author : pengyongshi"
)
call append(3,
"# * Email : 58217892@qq.com"
)
call append(4,
"# * Create time : "
.strftime(
"%Y-%m-%d %H:%M"
))
call append(5,
"# * Last modified : "
.strftime(
"%Y-%m-%d %H:%M"
))
call append(6,
"# * Filename : "
.
expand
(
"%:t"
))
call append(7,
"# * Description : "
)
call append(8,
"# **********************************************************"
)
endfunction
|
2.使用vim编辑.sh文件或.py文件全局模式下按F4键可以自动加入注释
本文转自 运维小学生 51CTO博客,原文链接:http://blog.51cto.com/yasar/1884953,如需转载请自行联系原作者