Sometimes when you write a program file, you often need to add some header comments, such as creator, creation date, version statement or function description, if you want to add a comment every time, it will be more troublesome, so you can create a new file with Vim, the header comments are added automatically.
1. C/C + +, Java Program files, and notes using "/* * * * *" for.
Vim vdi_connect.c
2. Create shell scripts, MK files, comments using "#"
Vim set_otg_usb_mode.sh
how VIM supports it.
to modify ~/.VIMRC, add the following at the end of the file:
"SetTitle function is automatically called when new .h .c .hpp .cpp .mk .sh and other files are created
autocmd BufNewFile *. [ch], *. hpp, *. cpp, Makefile, *. mk, *. sh exec ": call SetTitle ()"
"Add a note
func SetComment ()
call setline (1, "/ * ============================================== ====================== ")
call append (line ("."), "* Copyright (C)" .strftime ("% Y"). "Sangfor Ltd. All rights reserved.")
call append (line (".") + 1, "*")
call append (line (".") + 2, "* File name:" .expand ("%: t"))
call append (line (".") + 3, "* Creator: LuZhenrong")
call append (line (".") + 4, "* Creation date:" .strftime ("% Y year% m month% d day"))
call append (line (".") + 5, "* description:")
call append (line (".") + 6, "*")
call append (line (".") + 7, "===================================== =========================== * / ")
call append (line (".") + 8, "")
call append (line (".") + 9, "")
endfunc
"Add shell, Makefile comment
func SetComment_sh ()
call setline (3, "# =============================================== ===================== ")
call setline (4, "# Copyright (C)" .strftime ("% Y"). "Sangfor Ltd. All rights reserved.")
call setline (5, "#")
call setline (6, "# file name:" .expand ("%: t"))
call setline (7, "# Creator: LuZhenrong")
call setline (8, "# Creation date:" .strftime ("% Y year% m month% d day"))
call setline (9, "# description:")
call setline (10, "#")
call setline (11, "# =============================================== ===================== ")
call setline (12, "")
call setline (13, "")
endfunc
"Define the function SetTitle to automatically insert the file header
func SetTitle ()
if & filetype == 'make'
call setline (1, "")
call setline (2, "")
call SetComment_sh ()
elseif & filetype == 'sh'
call setline (1, "#! / system / bin / sh")
call setline (2, "")
call SetComment_sh ()
The
else
call SetComment ()
if expand ("%: e") == 'hpp'
call append (line (".") + 10, "#ifndef _". toupper (expand ("%: t: r")). "_ H")
call append (line (".") + 11, "#define _". toupper (expand ("%: t: r")). "_ H")
call append (line (".") + 12, "#ifdef __cplusplus")
call append (line (".") + 13, "extern \" C \ "")
call append (line (".") + 14, "{")
call append (line (".") + 15, "#endif")
call append (line (".") + 16, "")
call append (line (".") + 17, "#ifdef __cplusplus")
call append (line (".") + 18, "}")
call append (line (".") + 19, "#endif")
call append (line (".") + 20, "#endif //".toupper(expand("%:t:r"))."_H")
elseif expand ("%: e") == 'h'
call append (line (".") + 10, "#pragma once")
elseif & filetype == 'c'
call append (line (".") + 10, "# include \" ". expand ("%: t: r ").". h \ "")
elseif & filetype == 'cpp'
call append (line (".") + 10, "#include \" ". expand ("%: t: r ").". h \ "")
endif
endif
endfunc