VIM编写shell或者python脚本时自动添加脚本开头注释信息。

         每次写脚本的时候,都要写一堆脚本的开头注释信息,时间长了自然会繁琐那我们能不能来个偷懒呢?

偷懒的方法还是有的。那就是将下面的代码复制到~/.vimrc文件中,(放在任意位置。推荐放在末尾) ;如果没有.vimrc就新建一个。

autocmd BufNewFile *.py,*.sh, exec ":call SetTitle()"
let $author_name  = "zhangyong"
let $author_email = "zhangyong@xxxxxx.com"

func SetTitle()
if &filetype == 'sh'
call setline(1,"#!/bin/bash")
call append(line("."),   "#File Name    : ".expand("%"))
call append(line(".")+1, "#Author       : ".$author_name)
call append(line(".")+2, "#Mail         : ".$author_email)
call append(line(".")+3, "#Create Time  : ".strftime("%Y-%m-%d %H:%M"))
call append(line(".")+4, "#Description  : ")
call append(line(".")+5, "")
else
call setline(1,"#!/usr/bin/python")
call append(line("."),   "#File Name    : ".expand("%"))
call append(line(".")+1, "#Author       : ".$author_name)
call append(line(".")+2, "#Mail         : ".$author_email)
call append(line(".")+3, "#Create Time  : ".strftime("%Y-%m-%d %H:%M"))
call append(line(".")+4, "#Description  : ")
call append(line(".")+5, "")
endif
endfunc
autocmd BufNewfile * normal G

使用效果:

shell

python

 

 哈哈~这样每次写脚本的时候是不是方便很多呢?

 

原文地址:https://www.cnblogs.com/zyos/p/9213878.html