在日常写脚本或其他程序的时候,配置Vim让其在创建不同类型文件的时候添加相应的批注,这样会十分方便操作。
 
 
假设是以root为例,首先编辑/root/.vimrc文件,这个是root用户本地Vim环境变量配置文件,只对root生效。添加如下的内容:
 
autocmd BufNewFile *
.py exec
":call Python()"
func Python()
  
call append(
0,
"#!/usr/bin/env python")
  
call append(
1,
"# coding=utf-8")
  
call append(
2,
"#*******************************************")
  
call append(
3,
"# Author:  ")
  
call append(
4,
"# Date: " .strftime(
"%Y-%m-%d"))
  
call append(
5,
"# Filename: " .expand(
"%:t"))
  
call append(
6,
"# Describe: ")
endfunc
 
这一段代码的意思如下:
 
autocmd BufNewFile *.py exec":call Python()"
 
创建.py结尾的文件时执行Python()函数
 
call append  为每一行添加的内容。
 
.strftime("%Y-%m-%d")
 
显示时间
 
.expand("%:t")
 
显示文件名
 
 
以此类推,可以创建很多特定文件格式的注释信息,这样在创建新文件的时候会非常省事。