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

How to edit the vim configuration file so that the new file is automatically written to the file header

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article shows you how to edit the vim configuration file to make the new file automatically write to the header, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Because of the work need to often write shell script, every time to write the head of the script, just want to be lazy, every time you write the script can automatically generate the desired information, edit / etc/vimrc the file, some information will appear when adding .sh file

Autocmd BufNewFile * .sh exec ": call Setcomment ()"

Func Setcomment ()

Call append (0, "#! / bin/bash")

Call append (1, "# *")

Call append (2, "# * copyleft test" .strftime ("% Y-%m-%d"))

Call append (3, "# * scriptname:" .clients ("%"))

Call append (4, "# * email: sb@localhost")

Call append (5, "# * version: v0.1")

Call append (6, "# *")

Endfunc

=

Edit / etc/vimrc this file, some information will appear when you add .sh and .py files.

Autocmd BufNewFile * .py,*.sh, exec ": call SetTitle ()"

Let $author_name = "xxx"

Let $author_email = "xxx@xxx.xxx"

Func SetTitle ()

If & filetype = = 'sh'

Call setline (1, "\ #")

Call append (line ("."), "\ # File Name:" .clients ("%"))

Call append (line (".") + 1, "\ # Author:". $author_name)

Call append (line (".") + 2, "\ # mail:". $author_email)

Call append (line (".") + 3, "\ # Created Time:" .strftime ("% c"))

Call append (line (".") + 4, "\ # = =")

Call append (line (".") + 5, "\ #! / bin/bash")

Call append (line (".") + 6, ")

Else

Call setline (1, "\ #")

Call append (line ("."), "\ # File Name:" .clients ("%"))

Call append (line (".") + 1, "\ # Author:". $author_name)

Call append (line (".") + 2, "\ # mail:". $author_email)

Call append (line (".") + 3, "\ # Created Time:" .strftime ("% c"))

Call append (line (".") + 4, "\ # = =")

Call append (line (".") + 5, "\ #! / usr/bin/python")

Call append (line (".") + 6, ")

Endif

Endfunc

The above content is how to edit the vim configuration file to make the new file automatically write to the file header, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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

Servers

Wechat

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

12
Report