How to Use the keyboard F4 to automatically add scripts in the Vim Editor

Source: Internet
Author: User
Tags expression engine

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

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.