标签:
一、标题:vim 新建文件后自动插入模板
二、概要
无论是Linux系统管理员,还是linux开发程序员,都经常驻足于linux环境下的vi 编辑器编程开发。本篇分享,工作中的实用的编程工具技巧,可轻松一键搞定你设计想要的模板格式。
三、需求
在vi编辑器里,新建编码文件总是空白,有什么办法可以创建时,预先就指定对应的模板格式呢?怎么可以节省注释啊、编码格式啊、更新创建日期啊等等的备注呢?
四、实现
4.1 #vi ~/.vimrc (没有则新建一个 -rw-r--r--)
4.2 将以下内容存入,保存即可
syntax on set nocompatible "set number filetype on set history=1000 set background=dark "set autoindent "set smartindent set tabstop=4 set shiftwidth=4 set showmatch set guioptions-=T set ruler set nohls set incsearch "set fileencodings=utf-8 if &term=="xterm" set t_Co=8 set t_Sb=^[[4%dm set t_Sf=^[[3%dm endif function AddFileInformation_php() let infor = "<?php\n" \." ***************************************************************************\n" \." * \n" \." * Copyright (c) 2014 \n" \." * \n" \." **************************************************************************/ \n" \." \n" \." \n" \." \n" \."/** \n" \." * @file:".expand("%")." \n" \." * @author your name(Luolired@163.com) \n" \." * @date ".strftime("%Y-%m-%d %H:%M")." \n" \." * @version 1.0 \n" \." **/ \n" \." \n" \." \n" \." \n" \." \n" \." \n" \." \n" \."?>" silent put! =infor endfunction autocmd BufNewFile *.php call AddFileInformation_php() function AddFileInformation_sh() let infor = "#!/bin/bash\n" \."\n" \."# ***************************************************************************\n" \."# * \n" \."# * @file:".expand("%")." \n" \."# * @author:Luolired@163.com \n" \."# * @date:".strftime("%Y-%m-%d %H:%M")." \n" \."# * @version 1.0 \n" \."# * @description: Shell script \n" \."# * @Copyright (c) all right reserved \n" \."#* \n" \."#**************************************************************************/ \n" \."\n" \."\n" \."\n" \."\n" \."exit 0" silent put! =infor endfunction autocmd BufNewFile *.sh call AddFileInformation_sh() function AddFileInformation_py() let infor = "#!/usr/bin/env python\n" \."# -*- coding: utf-8 -*-\n" \."# ************************************************************************ \n" \."# * \n" \."# * @file:".expand("%")." \n" \."# * @author:Luolired@163.com \n" \."# * @date:".strftime("%Y-%m-%d %H:%M")." \n" \."# * @version 1.0 \n" \."# * @description: Python Script \n" \."# * @Copyright (c) all right reserved \n" \."# * \n" \."#************************************************************************* \n" \."\n" \."import os,sys" \."\n" \."print u‘‘‘中文‘‘‘\n" \."\n" \."exit()" silent put! =infor endfunction autocmd BufNewFile *.py call AddFileInformation_py()
五、总结
轻松搞定,新建php、python、sh等等插入模板格式。
良好的排版的格式,总是能让读者赏心悦目,格式的定义,就一步之遥,GTD!
标签:
原文地址:http://www.cnblogs.com/fiddler/p/4506260.html