Shell中一键添加作者,版权信息
第一步:编辑/etc/vimrc文件
[root@proxy ~]# cp /etc/vimrc /etc/vimrc.ori [root@proxy ~]# vim /etc/vimrc
第二步:直接在vimrc文件的最后添加如下的内容
map <F4> ms:call AddAuthor()<cr>'s function AddAuthor() let n=1 while n < 5 let line = getline(n) if line =~'^\s*\*\s*\S*Last\s*modified\s*:\s*\S*.*$' call UpdateTitle() return endif let n = n + 1 endwhile call AddTitle() endfunction function UpdateTitle() normal m' execute '/* Last modified\s*:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@' normal " normal mk execute '/* Filename\s*:/s@:.*$@\=": ".expand("%:t")@' execute "noh" normal 'k echohl WarningMsg | echo "Successful in updating the copy right." | echohl None endfunction function AddTitle() call append(0,"<<!") call append(1," **********************************************************") call append(2," * Author : Nuwanda") call append(3," * Email : 18348087798@163.com") call append(4," * Last modified : ".strftime("%Y-%m-%d %H:%M")) call append(5," * Filename : ".expand("%:t")) call append(6," * Description : ") call append(7," * *******************************************************") call append(8,"!") echohl WarningMsg | echo "Successful in adding the copyright." | echohl None endfunction
第三步:使用vim新建文件的时候在命令模式下,实现F4一键添加作者,版权信息
<<! ********************************************************** * Author : Nuwanda * Email : 18348087798@163.com * Last modified : 2016-01-13 00:20 * Filename : test * Description : * ******************************************************* !