Add text messages automatically by adding comments in vim

Source: Internet
Author: User

工欲善其事, its prerequisite. In the development process, convenient and fast development environment, can improve work efficiency; A beautiful interface can make us happy, and most importantly, to keep us in the deep and unpredictable of the layman ~

If you want to automatically generate some comments when you create a new source program file, such as author, date created, contact, and so on, you can do this:

Edit the ~/.VIMRC file and add the code:  

Autocmd Bufnewfile *. [Ch],*.hpp,*.cpp exec]: Call Settitle () "Func setcomment () call Setline (1,"/***************************************** ") Call Append (". ")," * Copyright (C) ". Strftime ("%Y ")." All rights reserved. ") Call Append (".") +1, "*") Call Append (".") +2, "* Filename:". Expand ("%:t")) Call Append (".") +3, "* Author: [email protected]") Call Append (".") +4, "* Date:". Strftime ("%y-%m-%d")) Call Append (".") +5, "* Describe:") Call Append (".") +6, "*") Call Append (".") +7, "********************************************************/") Endfuncfunc Settitle () call SetComment () if expand (" %:e ") = = ' HPP ' Call Append (". ") +8, "#ifndef _". ToUpper (Expand ("%:t:r")). " _h ") Call Append (". ") +9, "#define _". ToUpper (Expand ("%:t:r")). " _h ") Call Append (". ") +10, "#ifdef __cplusplus") Call Append (".") +11, "extern \" C\ "") Call Append (".") +12, "{") Call Append (".") +13, "#endif") Call Append (".") +14, "")Call Append (".") +15, "#ifdef __cplusplus") Call Append (".") +16, "}") Call Append (".") +17, "#endif") Call Append (".") +18, "#endif//". ToUpper (Expand ("%:t:r")). " _h ") ElseIf expand ("%:e ") = = ' H ' Call Append (". ") +8, "#ifndef _". ToUpper (Expand ("%:t:r")). " _h ") Call Append (". ") +9, "#define _". ToUpper (Expand ("%:t:r")). " _h ") Call Append (". ") +10, "") Call Append (".") +11, "#endif") Call Append (".") +12, "#endif//". ToUpper (Expand ("%:t:r")). " _h ") elseif &filetype = = ' C ' Call append (". ") +8, "#include \" ". Expand ("%:t:r ").". H\ "") elseif &filetype = = ' cpp ' Call append (".") +8, "#include \" ". Expand ("%:t:r ").". H\ "") Endifendfunc

Vim multi-line comment and delete multiline comment-------------------------------------------------------------------------------1. Multi-line Comment: A. Press CTRL +  V, enter the column mode;  B. At the beginning of the line, select the lines that need comment; C. Press "I" to enter insert mode;
D. Then enter the comment symbol ("//", "#", etc.); E. Press the "ESC" key.
2. Delete Multiline comment: A. Press CTRL + V to enter the column mode;  B. Select the annotation you want to cancel; C. Press "X" or "D".

Add text messages automatically by adding comments 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.