工欲善其事, 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