Vim how to automatically add a code file header

Source: Internet
Author: User
Tags regular expression reserved

First of all, thanks to the online Daniel:

http://www.vimer.cn/

And this brother: http://www.oschina.net/code/snippet_103341_9644

How can I have Ubuntu without vim?

Then the first tease than the now Windows installed Gvim ...

Sure enough, the medicine can't stop ...

A good version of the Portal: "Baidu Cloud" Http://pan.baidu.com/s/1qWntcEK

And then just add the header of the file. This from Vimer Daniel's blog to learn a lot of posture, but helpless I was too weak regular expression will not ... Daniel uses regular expressions to match, I am a direct string match .... To kneel.

By the way, give us some information:

Add path and file Http://vim.wikia.com/wiki/Insert_current_filename

This is Vim's setup code, which binds F4 to add or update file headers.

The main structure is the Daniel's ... I was just very anxious to change a little bit ...

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

"Make copyright notice Settings" Add or update header map <F4>: Call Titledet () <cr> ' s function addtitle () call append (0, "/*=======   
    ====================================================================== ") Call Append (1," # COPYRIGHT NOTICE ") Call Append (2, "# Copyright (c) 2014") called Append (3, "# All rights reserved") call Appen D (4, "#") Call Append (5, "# @author: Shen") Call Append (6, "# @name:") cal L Append (7, "# @file:". Expand ("%:p: H"). "       \ ". Expand ("%:t ")) call Append (8," # @date: ". Strftime ("%y/%m/%d%h:%m ")) call Append (9," # @algorithm: ") call Append (10," ============================================================================= * ") Call append (one," ") Echohl warningmsg | echo "Successful in adding the copyright." |     Echohl None ENDF Update recently modified time and filename function updatetitle () normal m ' Execute '/# @date /s@:.*$@\=strftime (":%y-%m-%d%h:%m") @ ' normal ' normal Mk Execute '/# @file/s@:.*$@\= ":". Expa nd ("%:p: H"). " \ \ ". Expand ("%:t ") @ ' execute ' noh ' normal ' k Echohl warningmsg | echo "Successful in updating the copy right." | Echohl None endfunction "Judge the first 10 lines of code, whether there is the word" copyright notice, "if not, the representative did not add the author information, need to add;" If there is, then only need to update to Functio 
        n Titledet () Let n = 2 "default to add let line = Getline (n) Let str = ' ^# COPYRIGHT notice$ ' If line =~ str call Updatetitle () return endif call AddTitle () Endfun Ction

And then incidentally attach the result:

/*=============================================================================  
#       COPYRIGHT NOTICE  
#       Copyright (c) 2014  
# all       rights Reserved # #       @author       : Shen  
#       @name         :  
#       @file         : G:\My Source code\defaultcode.cpp  
#       @date         : 2014/06/10 18:06  
#       @ Algorithm    :  
=============================================================================*/

In fact, you can also do according to different files to add different code headers ... The workload is a bit large, and the weak mainly write a C + +, and then did not do.

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.