Skip to content

Commit 626eb05

Browse files
author
Ma Weiwei
committed
Merge pull request ma6174#44 from guodongxiaren/master
增加.h头文件自动生成的内容
2 parents 7278383 + 06d298f commit 626eb05

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

.vimrc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ nmap tt :%s/\t/ /g<CR>
111111
"""""新文件标题
112112
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
113113
"新建.c,.h,.sh,.java文件,自动插入文件头
114-
autocmd BufNewFile *.cpp,*.c,*.sh,*.rb,*.java,*.py exec ":call SetTitle()"
114+
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()"
115115
""定义函数SetTitle,自动插入文件头
116116
func SetTitle()
117117
"如果文件类型为.sh文件
@@ -139,7 +139,7 @@ func SetTitle()
139139
call append(line(".")+4, " ************************************************************************/")
140140
call append(line(".")+5, "")
141141
endif
142-
if &filetype == 'cpp'
142+
if expand("%:e") == 'cpp'
143143
call append(line(".")+6, "#include<iostream>")
144144
call append(line(".")+7, "using namespace std;")
145145
call append(line(".")+8, "")
@@ -148,6 +148,11 @@ func SetTitle()
148148
call append(line(".")+6, "#include<stdio.h>")
149149
call append(line(".")+7, "")
150150
endif
151+
if expand("%:e") == 'h'
152+
call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
153+
call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
154+
call append(line(".")+8, "#endif")
155+
endif
151156
if &filetype == 'java'
152157
call append(line(".")+6,"public class ".expand("%:r"))
153158
call append(line(".")+7,"")

0 commit comments

Comments
 (0)