VIM编辑新文件自动添加头文件信息

 ###############################################################################
# Name : Mahavairocana                                                                                                                                           
# Author : Mahavairocana                                                                                                                                         
# QQ : 10353512                                                                                                                                                    
# WeChat : shenlan-qianlan                                                                                                                                      
# Blog : http://www.cnblogs.com/Mahavairocana/                                                                                                       
# Description : You are welcome to reprint, or hyperlinks to indicate the                                                                        
#                    source of the article, as well as author information.                                                                                ###############################################################################

把如下文件直接贴到root目录下,在编辑新文件的时候显示自定义信息。

root@shenlan-qianlan:/home/python/day1# vim shenlanqianlan.sh
#!/bin/bash
#########################################################################
# File Name: shenlanqianlan.sh
# Author : Mahavairocana  
# QQ : 10353512
# Email:10353512@qq.com
# Blog:http://www.cnblogs.com/shenlanqianlan/
# Created Time: Wednesday, October 19, 2016 PM05:02:49 HKT
#########################################################################

 

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

root@shenlan-qianlan:~# cat .vimrc 
let g:pydiction_location = '~/.vim/after/complete-dict'
let g:pydiction_menu_height = 20
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

autocmd FileType python set omnifunc=pythoncomplete#Complete
 
set rtp+=~/.vim/bundle/vundle
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
set fileencoding=utf-8
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""新文件标题""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自动插入文件头 
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.py,*.java exec ":call SetTitle()" 
""定义函数SetTitle,自动插入文件头 
func SetTitle() 
    "如果文件类型为.sh文件 
    if &filetype == 'sh' 
        call setline(1,"\#!/bin/bash") 
        call append(line("."),"\#########################################################################") 
        call append(line(".")+1, "\# File Name: ".expand("%"))
        call append(line(".")+2, "\# Author : Mahavairocana")
        call append(line(".")+3, "\# QQ : 10353512")
        call append(line(".")+4, "\# Email:10353512@qq.com")
        call append(line(".")+5, "\# Blog:http://www.cnblogs.com/shenlanqianlan/")
        call append(line(".")+6, "\# Created Time: ".strftime("%c"))
        call append(line(".")+7, "\#########################################################################")
        call append(line(".")+8, "")

    elseif &filetype == 'python'
        call setline(1,"\#!/usr/bin/env python")
        call append(line("."),"\#########################################################################")
        call append(line(".")+1, "\# File Name: ".expand("%"))
        call append(line(".")+2, "\# Author :刘琪")
        call append(line(".")+3, "\# QQ : 10353512")
        call append(line(".")+4, "\# Email:10353512@qq.com")
        call append(line(".")+5, "\# Blog:http://www.cnblogs.com/shenlanqianlan/")
        call append(line(".")+6, "\# Created Time: ".strftime("%c"))
        call append(line(".")+7, "\#########################################################################")
        call append(line(".")+8, "")

    else
        call setline(1, "/*************************************************************************") 
        call append(line("."), "    > File Name: ".expand("%")) 
        call append(line(".")+1, "\# File Name: ".expand("%"))
        call append(line(".")+2, "\# Author : Mahavairocana  ")
        call append(line(".")+3, "\# QQ : 10353512")
        call append(line(".")+4, "\# Email:10353512@qq.com")
        call append(line(".")+5, "\# Blog:http://www.cnblogs.com/shenlanqianlan/")
        call append(line(".")+6, "\# Created Time: ".strftime("%c"))
        call append(line(".")+7, " ************************************************************************/") 
        call append(line(".")+8, "")

    endif
    if &filetype == 'cpp'
        call append(line(".")+6, "#include<iostream>")
        call append(line(".")+7, "using namespace std;")
        call append(line(".")+8, "")
    endif
    if &filetype == 'c'
        call append(line(".")+6, "#include<stdio.h>")
        call append(line(".")+7, "")
    endif
    "新建文件后,自动定位到文件末尾
endfunc 
autocmd BufNewFile * normal G

 

posted on 2016-10-19 17:03  Mahavairocana  阅读(2738)  评论(0编辑  收藏  举报

导航