Vim is automatically configured to add copyright information when scripting

Source: Internet
Author: User

When you write a script, you can add copyright information so that the maximum usability of the script is where the individual labor is

The following is the automatic configuration to add copyright information when Vim writes a script

Edit in the user's home directory (typically the root directory). VIMRC (note is hidden file)

Edit the following (if there is a problem with the copy format, copy the VIMRC of the attachment and rename it to. vimrc)

Map <F4>: Call Titledet () <cr>
function AddTitle ()
Call Append (0, "\#!/bin/bash") # #编辑解释器
Call Append (1, "# ******************************************************")
Call Append (2, "# Author:sunjian") # #作者名称
Call Append (3, "# Last Modified:". Strftime ("%y-%m-%d%h:%m") # #上次修改时间
Call Append (4, "# Email: [Email protected]") # #邮箱地址
Call Append (5, "# Filename:". Expand ("%:t")) # #文件名
Call Append (6, "# Description:") # #描述
Call Append (7, "# ******************************************************")
Echohl warningmsg | echo "Successful in adding copyright." | Echohl None
Endf

function Updatetitle ()
Normal m '
Execute '/# last Modified/[email protected]:.*[email protected]\=strftime (": \t%y-%m-%d%h:%m") @ '
Normal "
Normal MK
Execute '/# filename/[email protected]:.*[email protected]\= ": \ T". Expand ("%:t") @ '
Execute "Noh"
Normal ' k
Echohl warningmsg | echo "Successful in updating the copyright." | Echohl None
Endfunction

function Titledet ()
Let N=1
While N < 10
Let line = Getline (n)
If line =~ ' ^\#\s*\s*last\smodified\s*.*$ '
Call Updatetitle ()
Return
endif
Let n = n + 1
Endwhile
Call AddTitle ()
Endfunction

Save exit after Edit

Edit the new file test.sh, press F4 in Norm (standard) mode, the effect is as follows:

#!/bin/bash
# ******************************************************
# Author:sunjian
# Last modified:2016-08-03 10:05
# email: [Email protected]
# Filename:test.sh
# Description:
# ******************************************************

If the file name is changed to TEST2.S h, then need to update the above information, only need: MV test.sh test2.sh, then vim test2.sh, press in Norm (standard) mode F4, The modified time and file name are automatically updated

#!/bin/sh
# ******************************************************
# Author:sunjian
# Last modified:2016-08-03 10:08
# email: [Email protected]
# Filename:test1.sh
# Description:
# ******************************************************


This article is from the "Lonely No Color" blog, please be sure to keep this source http://tenderness.blog.51cto.com/8855468/1954383

Vim is automatically configured to add copyright information when scripting

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.