为vim编辑器添加默认的作者信息
来源:互联网 发布:0基础大数据培训多少钱 编辑:程序博客网 时间:2024/05/14 12:58
修改/etc/vimrc配置文件,在文件末尾添加如下内容即可
" 侦测文件类型filetype on" 载入文件类型插件filetype plugin on""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""新文件标题"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""新建.c,.h,.sh,.java文件,自动插入文件头 autocmd BufNewFile *.cpp,*.[ch] exec ":call SetTitleC()" autocmd BufNewFile *.sh exec ":call SetTitleSh()" autocmd BufNewFile *.php exec ":call SetTitlePhp()" autocmd BufNewFile *.py exec ":call SetTitlePy()" autocmd BufNewFile *.html,*.htm,*.phtml exec ":call SetTitleHtml()" autocmd BufNewFile *.css exec ":call SetTitleCss()" autocmd BufNewFile *.java exec ":call SetTitleJava()" ""定义函数SetTitle,自动插入文件头func SetTitle() call setline(1, "#/*************************************************************************") call append(line("."), "# > File Name: ".expand("%")) call append(line(".")+1, "# > Author: liyong") call append(line(".")+2, "# > Mail: 2550702985@qq.com") call append(line(".")+3, "# > Created Time: ".strftime("%Y-%m-%d %H:%M")) call append(line(".")+4, "# > Modified Time: ".strftime("%Y-%m-%d %H:%M")) call append(line(".")+5, "# ************************************************************************/")endfuncfunc SetTitleC() call SetTitle() call append(line(".")+6, "#include<stdio.h>") call append(line(".")+7, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal Gendfunc func SetTitleSh() call SetTitle() call append(line(".")+6, "\#!/bin/bash") call append(line(".")+7, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal Gendfunc func SetTitlePhp() call SetTitle() call append(line(".")+6, "<?php") call append(line(".")+7, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal Gendfunc func SetTitlePy() call SetTitle() call append(line(".")+6, "#!/usr/bin/env python") call append(line(".")+7, "# -*- coding: utf-8 -*-") call append(line(".")+8, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal Gendfuncfunc SetTitleHtml() call setline(1, "<!DOCTYPE HTML>") call append(line(".")+1, "<html lang="en-US">") call append(line(".")+2, "<head>") call append(line(".")+3, " <meta charset="UTF-8">") call append(line(".")+4, " <title></title>") call append(line(".")+5, "</head>") call append(line(".")+6, "<body>") call append(line(".")+7, "</body>") call append(line(".")+8, "</html>") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal Gendfuncfunc SetTitleCss() call setline(1, "@charset 'utf-8'") call append(line("."), "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal Gendfuncfunc SetTitleJava() call SetTitle() call append(line(".")+6, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal Gendfuncfunc SetFileTitle() "如果文件类型为.sh文件 if &filetype == 'sh' call setline(1,"\#########################################################################") call append(line("."), "\# File Name: ".expand("%")) call append(line(".")+1, "\# Author: ma6174") call append(line(".")+2, "\# mail: ma6174@163.com") call append(line(".")+3, "\# Created Time: ".strftime("%Y-%m-%d %H:%M")) call append(line(".")+4, "\# Description: " call append(line(".")+5, "\#########################################################################") call append(line(".")+6, "\#!/bin/bash") call append(line(".")+7, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name: ".expand("%")) call append(line(".")+1, " > Author: liyong") call append(line(".")+2, " > Mail: 2550702985@qq") call append(line(".")+3, " > Created Time: ".strftime("%Y-%m-%d %H:%M")) call append(line(".")+4, " ************************************************************************/") call append(line(".")+5, "") endif "如果文件类型为.py文件 if &filetype == 'py' call append(line(".")+6, "#!/usr/bin/env python") call append(line(".")+7, "# -*- coding: utf-8 -*-") endif "如果文件类型为.php文件 if &filetype == 'php' call append(line(".")+6, "<?php") endif "如果文件类型为.html文件 if &filetype == 'html' call append(line(".")+6, "<!DOCTYPE HTML>") call append(line(".")+7, "<html lang="en-US">") call append(line(".")+8, "<head>") call append(line(".")+9, " <meta charset="UTF-8">") call append(line(".")+10, " <title></title>") call append(line(".")+11, "</head>") call append(line(".")+12, "<body>") call append(line(".")+13, "</body>") call append(line(".")+14, "</html>") endif "如果文件类型为.css文件 if &filetype == 'css' call setline(1, "@charset 'utf-8'") endif if &filetype == 'cpp' call append(line(".")+6, "#include<iostream>") call append(line(".")+7, "using namespace std;") call append(line(".")+8, "") endif if &filetype == 'c' call append(line(".")+6, "#include<stdio.h>") call append(line(".")+7, "") endif "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal Gendfunc "将键盘上的F4功能键映射为添加作者信息的快捷键 map <F4> ms:call TitleDet()<cr>'s function AddTitle() call append(0,"/*******************************************************************************") call append(1," * Author :liyong") call append(2," * Email : 2550702985@qq.com") call append(3," * Last modified : ".strftime("%Y-%m-%d %H:%M")) call append(4," * Filename : ".expand("%:t")) call append(5," * Description : ") call append(6," * *****************************************************************************/") echohl WarningMsg | echo "Successful in adding the copyright." | echohl None endfunction function UpdateTitle() normal m' execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@' normal " normal mk execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@' execute "noh" normal 'k echohl WarningMsg | echo "Successful in updating the copy right."| echohl None endfunctionfunction TitleDet() let n=1 while n < 10 let line = getline(n) if line =~'^\#\s*\S*Last\smodified:\S*.*$' call UpdateTitle() return endif let n = n + 1 endwhile call AddTitle() endfunction
0 0
- 为vim编辑器添加默认的作者信息
- Linux下vim编辑器设置自动添加作者信息
- VIM配置自动添加作者信息
- 修改git默认的编辑器nano为vim的方法
- 自动为Myeclipse添加作者等信息
- 修改ubuntu默认编辑器为vim
- Raspberry - 修改crontab默认编辑器为vim
- 修改ubuntu默认编辑器为vim
- ubuntu修改默认文本编辑器为vim
- vim中自动添加文件的作者、时间信息、版本等
- vim中自动添加文件的作者、时间信息、版本等
- 配置vim在源码中自动添加作者信息
- 配置vim在源码中F4/自动添加作者信息
- vim中自动添加作者时间等信息
- 为VS2008默认模板添加版权信息
- 为VS2010默认模板添加版权信息
- 为VS2010默认模板添加版权信息
- 为VisualStudio默认模板添加版权信息
- 自定义分页
- HDU4080后缀数组
- 张量展开与tensor tool box
- Sqoop安装和使用
- $(this)与this的区别
- 为vim编辑器添加默认的作者信息
- URAL 2021. Scarily interesting!(*贪心? set整理)
- 2016年农民工监测调查报告(zz)
- 递归(循环)神经网络(RNN)简介
- Systick滴答定时器-延时函数
- 摄影测量空间后方交会外方位元素的解算程序
- 1031: 求车速
- FastJson 使用
- mysql高可用方案对比