为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