为vim编辑器添加默认的作者信息
2017-05-02 12:56
155 查看
修改/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, "# ************************************************************************/") endfunc func SetTitleC() call SetTitle() call append(line(".")+6, "#include<stdio.h>") call append(line(".")+7, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G endfunc func SetTitleSh() call SetTitle() call append(line(".")+6, "\#!/bin/bash") call append(line(".")+7, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G endfunc func SetTitlePhp() call SetTitle() call append(line(".")+6, "<?php") call append(line(".")+7, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G endfunc 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 G endfunc func 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 G endfunc func SetTitleCss() call setline(1, "@charset 'utf-8'") call append(line("."), "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G endfunc func SetTitleJava() call SetTitle() call append(line(".")+6, "") "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G endfunc func 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 G endfunc "将键盘上的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 endfunction function 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
相关文章推荐
- 为vim编辑器添加默认的作者信息
- vim编辑器添加默认的作者信息
- Linux下vim编辑器设置自动添加作者信息
- 配置vim在源码中自动添加作者信息
- 新建vim脚本自动添加作者信息(脚本)
- vim--如何添加作者信息
- vim中自动添加文件的作者、时间信息、版本等
- Vim中自动在程序起始处添加版权和作者信息
- PyCharm新建.py文件时默认添加作者时间等信息
- vim编辑器添加头信息
- vim自动添加作者信息、注释
- 配置vim在源代码中自动添加作者信息
- vim中自动添加文件的作者、时间信息、版本等
- vim在源码中自动添加作者信息
- 配置vim在源码中F4/自动添加作者信息
- Pycharm 设置模板默认添加作者时间等信息
- linux定时任务crontab--虚拟机ubuntu在添加定时任务的时候,如何取消nano的默认编辑,改用vim编辑器
- 在vim下按F4自动添加作者信息,文件创作时间等
- Vim中自动在程序起始处添加版权和作者信息
- VIM配置自动添加作者信息