How can I configure vim to automatically add the script running environment, author, email, script description, and other information during shell script development using vim? I found some information online, and finally found some information. paste the vimrc configuration file.
Cat ~ /. Vimrc
"Set the copyright statement
"Add or update Headers
"Map the F4 function key on the keyboard to the shortcut key for adding the author information
Map <F4>: call TitleDet () <cr>'s
Function AddTitle ()
Call append (0 ,"#! /Bin/sh ")
Call append (1, "# Filename:". expand ("%: t "))
Call append (2, "# Author: zhangliang-z_liang90@126.com ")
Call append (3, "# QQ: 295029531 ")
Call append (4, "# Last modified:". strftime ("% Y-% m-% d % H: % M "))
Call append (5, "# Description :")
"Echohl WarningMsg | echo" Successful in adding the copyright. "| echohl None
Endf
"Updated last modification time and file name
Function UpdateTitle ()
Normal m'
Execute '/# * Last modified:/s @:. * $ @ \ = strftime (": % Y-% m-% d % H: % M ")@'
Normal''
Normal mk
Execute '/# * Filename:/s @:. * $ @ \ = ":". expand ("%: t ")@'
Execute "noh"
Normal 'K
"Echohl WarningMsg | echo" Successful in updating the copy right. "| echohl None
Endfunction
"Determine whether the Last modified word exists in the first 10 lines of code,
"If not, it indicates that the author information has not been added and needs to be added;
"If yes, you only need to update it.
Function TitleDet ()
Let n = 1
"Add by default
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
After saving the information, edit an x. sh script file and press the F4 key. The information can be automatically added. Just change the specific information!
Recommended reading:
Vim Learning Guide
Quick learn Vi Editor
Powerful Vim Editor
Build a Vim Development Environment on CentOS 6.2
Vim 7.4a released, a new and faster Regular Expression Engine
Install the highlighted Vim editing tool in CentOS 5.4
Vim tips: C language settings
Set the Vim row number in Ubuntu
Vim editor basic tutorial