Automatically add comments to add text information in vim

Source: Internet
Author: User

Automatically add comments to add text information in vim
To do well, you must first sharpen your tools. In the development process, a convenient and quick development environment can improve work efficiency. A beautiful interface can make us feel happy. The most important thing is that, we can keep ourselves in a difficult and unpredictable place ~

If you want to automatically generate comments when creating a source program file, such as the author, creation date, and contact information, you can do this:

Edit ~ /. Vimrc file, add the Code:

autocmd BufNewFile *.[ch],*.hpp,*.cpp exec ":call SetTitle()" func SetComment()call setline(1,"/********************************************************") call append(line("."),   "*   Copyright (C) ".strftime("%Y")." All rights reserved.")call append(line(".")+1, "*   ") call append(line(".")+2, "*   Filename:".expand("%:t")) call append(line(".")+3, "*   Author  :wang@xd")call append(line(".")+4, "*   Date    :".strftime("%Y-%m-%d")) call append(line(".")+5, "*   Describe:") call append(line(".")+6, "*")call append(line(".")+7, "********************************************************/") endfuncfunc SetTitle()call SetComment()if expand("%:e") == 'hpp' call append(line(".")+8, "#ifndef _".toupper(expand("%:t:r"))."_H") call append(line(".")+9, "#define _".toupper(expand("%:t:r"))."_H") call append(line(".")+10, "#ifdef __cplusplus") call append(line(".")+11, "extern \"C\"") call append(line(".")+12, "{") call append(line(".")+13, "#endif") call append(line(".")+14, "") call append(line(".")+15, "#ifdef __cplusplus") call append(line(".")+16, "}") call append(line(".")+17, "#endif") call append(line(".")+18, "#endif //".toupper(expand("%:t:r"))."_H") elseif expand("%:e") == 'h' call append(line(".")+8, "#ifndef _".toupper(expand("%:t:r"))."_H") call append(line(".")+9, "#define _".toupper(expand("%:t:r"))."_H") call append(line(".")+10," ") call append(line(".")+11, "#endif") call append(line(".")+12, "#endif //".toupper(expand("%:t:r"))."_H") elseif &filetype == 'c' call append(line(".")+8,"#include \"".expand("%:t:r").".h\"") elseif &filetype == 'cpp' call append(line(".")+8, "#include \"".expand("%:t:r").".h\"") endifendfunc
Vim multi-line comment and delete multi-line comment ----------------------------------------------------------------------------- 1. multi-line comment:. press Ctrl + v to enter the column mode. B. select the line to be commented at the beginning of the line; c. press "I" to enter the insert mode;
D. Enter the annotator ("//", "#", etc.); e. Press the "Esc" key.
2. delete comments from multiple rows: a. Press Ctrl + v to enter the column mode; B. Select the comments to be canceled; c. Press "x" or "d ".

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.