Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The vim editor adds default author information

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

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: ##############################################

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report