Automatically add copyright and author information to the beginning of the program in VIM

Source: Internet
Author: User

When writing a program, it is often necessary to start writing a brief introduction to the program and the author's information, as follows:

This kind of information, in addition to the file name and modification time may often change, other basic unchanged, can be automatically added in the program, the method is in the home directory. VIMRC write:

Map <F4>: Call Titledet () <cr>functionaddtitle () call Append (0,"\#!/usr/bin/env Bash") Call Append (1,"# ******************************************************") Call Append (2,"# Author:90zeng") 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 noneendffunctionupdatetitle () 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'kEchohl warningmsg |Echo "successful in updating the copyright."|Echohl noneendfunctionfunctionTitledet () Let n=1     whileN <Ten Let Line=getline (n)ifLine =~'^\#\s*\s*last\smodified\s*.*$'Call Updatetitle () return endif let n= n +1Endwhile Call AddTitle () endfunction
View Code

After saving, vi test.sh, in norm Mode press F4 can, the effect is as follows:

If the next moment, we will change the file name to test2.sh, and then need to update the above information, only need: MV test.sh test2.sh, and then Vim Test2.sh,f4, will automatically update the modified time and file name

If we often need to write Python files, then modify the corresponding characters in the. VIMRC, as follows:

The effect is as follows:

There is already a plug-in implementation of the above functions (http://www.vim.org/scripts/script.php?script_id=2902), but for the installation of the plug-in inconvenient scenes, you can manually write the above code

Reference: Vim automatically adds author information in source code

Automatically add copyright and author information to the beginning of the program in VIM

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.