The vim editor adds default author information
Many programmers want to add some author information to their programs, so how should we achieve this requirement?
For example, shell script, just modify the/etc/vimrc configuration file and add the following at the end of the file
Note: in vimrc file, comment line is marked with ", otherwise error will be reported
Copy comment lines individually, code segments can be copied together, otherwise it will cause incorrect indentation
"Add author information when pressing F4, if you need to add a python you can add F5map ms:call TitleDet()'sfunction AddTitle() call append(0,"#!/ bin/bash") call append(1,"##############################################") call append(2,"#Author: Liuzhengwei - 1135960569@qq.com") call append(3,"#QQ:1135960569") call append(4,"#Last modified: ".strftime("%Y-%m-%d %H:%M")) call append(5,"#Filename: ".expand("%:t")) call append(6,"#Description: ") call append(7,"##############################################") echohl WarningMsg | echo "Successful in adding the copyright. " |echohl Noneendfunction"modify file modification time and file name function UpdateTitle() normal m' execute '/#*Last modified:/s@:.*$@\= strftime(":%Y-%m-%d %H:%M")@' normal '' normal mk execute '/#*Filename:/s@:.*$@\= ":".expand("%:t")@' execute "noh" normal 'k echohl WarningMsg | echo "Successful in updating the copy right. " |echohl Noneendfunction"Judge if there is Last modified: field in the first 10 lines" If there is no, it means that the author information and other conditions have not been added, then add again "If there is, then only update the modification time and file name function TitleDet() let n=1 while n < 7 let line = getline(n) if line =~ '^\#\s*\S*Last\smodified:\S*.*$ ' call UpdateTitle() return endif let n = n + 1 endwhile call AddTitle()endfunction
After adding, open a test.sh file, press F4 and the following message will appear.
[root@test3 tmp]# vim test.sh#!/ bin/bash###############################################Author: Liuzhengwei - 1135960569@qq.com#QQ:1135960569#Last modified: 2016-07-04 15:55#Filename: test.sh#Description: ##############################################