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