vi自动化命令之自动给新建的文件添加注释
2017-11-23 13:52
489 查看
vi自动化命令之自动给新建的文件添加注释
操作: 将下面的代码复制到~/.vimrc文件中,(放在任意位置。推荐放在末尾)
没有.vimrc就新建一个
功能:
当新建.c,.cpp,.sh,.py,*.java文件时会自动添加相依的头文件信息
autocmd BufNewFile *.c,*.cpp,*.sh,*.py,*.java exec ":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
相关文章推荐
- vi技巧之自动给新建的文件添加头部注释
- Eclipse和Android Studio新建文件时自动添加注释
- MyEclipse新建文件时自动添加注释
- svn不能自动添加新建的文件
- MyEclipse自动添加头时间、作者、文件注释等。
- C#&VB.NET自动添加文件注释的方法
- 一个很有用的vimrc文件(添加抬头,产生cpp初始程序,添加注释,注释一行,自动K&R格式化,taglist)
- vi命令,替换操作,文本格式转换,在整个文件中替换,在行首尾添加字符串
- vim中自动添加文件注释到文本中
- Pycharm在创建py文件时,如何自动添加文件头注释?
- Pycharm在创建py文件时,自动添加文件头注释的实例
- 在C#类文件 自动添加文件注释的方法
- idea创建新的类(文件)时,自动添加作者创建时间(文件注释)等信息的设置方法
- Eclipse新建类的时候如何自动添加注释(作者,时间的信息
- 如何给我们的eclipse新建文件自动生成注释
- eclipse新建java文件时自动生成注释
- VS新建类自动添加版本注释
- 在Eclipse中为新建java文件自动添加文件头
- eclipse 新建 java 文件时自动生成注释
- vi部分命令. 替换操作; 文本格式转换; 在整个文件中替换; 在行首尾添加字符串.