vi自動化命令之自動給新建的檔案添加註釋
阿新 • • 發佈:2019-02-13
call SetTitle()"
"定義函式SetTitle,自動插入檔案頭
func SetTitle()
"如果檔案型別為.c或者.cpp檔案
if (&filetype == 'c' || &filetype == 'cpp')
call setline(1, "/*************************************************************************")
call setline(2, " \ @Author: 你的名字")
call setline(3, "\ @Created Time : ".strftime("%c"))
call setline(4, "\ @File Name: ".expand("%"))
call setline(5, "\ @Description:")
call setline(6, " ************************************************************************/")
call setline(7,"")
endif
" 如果檔案型別為.sh檔案
if &filetype == 'shell'
call setline(1, "\#!/bin/sh")
call setline(2, "\# Author: 你的名字")
call setline(3, "\# Created Time : ".strftime("%c"))
call setline(4, "\# File Name: ".expand("%"))
call setline(5 , "\# Description:")
call setline(6,"")
endif
"如果檔案型別為.py檔案
if &filetype == 'python'
call setline(1, "\#!/usr/bin/env python")
call setline(2, "\# -*- coding=utf8 -*-")
call setline(3, "\"\"\"")
call setline(4, "\# Author: 你的名字")
call setline(5, "\# Created Time : ".strftime("%c"))
call setline(6, "\# File Name: ".expand("%"))
call setline(7, "\# Description:")
call setline(8, "\"\"\"")
call setline(9,"")
endif
"如果檔案型別為.java檔案
if &filetype == 'java'
call setline(1, "//coding=utf8")
call setline(2, "/**")
call setline(3, "\ *\ @Author: 你的名字")
call setline(4, "\ *\ @Created Time : ".strftime("%c"))
call setline(5, "\ *\ @File Name: ".expand("%"))
call setline(6, "\ *\ @Description:")
call setline(7, "\ */")
call setline(8,"")
endif
endfunc
" 自動將游標移動到檔案末尾
autocmd BufNewfile * normal G