Get the App
SLTechnology News&Howtos  ›  Servers  › 

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

Shulou Source: shulou.com Published: 2022-06-01 03:05:48 09月28日 Update

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.

Tags: Files information time scripts configuration content skills knowledge concise to the point that is articles more articles automatic generation industry information information channels channels one bright Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Shulou Technology MariaDB Huawei