美文网首页
vi一键添加脚本信息

vi一键添加脚本信息

作者: 桩i | 来源:发表于2017-11-17 19:08 被阅读0次

    对于经常写脚本的人,有些内容可能每个脚本中都会出现,例如

    #!/bin/bash
    ####################################
    # Date: 2017-11-17                                       
    # Author: benJK                                            
    # Description: You know what i mean,hehe  
    ####################################
    

    所以就记录一下,如何自动将信息填入脚本中

    F4键添加自定义信息

    在用户家目录下编辑文件(没有就新建)

     ]# vi  ~/.vimrc
    map <F4> ms:call AddAuthor()<cr>'s
    
    function AddAuthor()
            let n=1
            while n < 5
                    let line = getline(n)
                    if line =~'^\s*\*\s*\S*Last\s*modified\s*:\s*\S*.*$'
                            call UpdateTitle()
                            return
                    endif
                    let n = n + 1
            endwhile
            call AddTitle()
    endfunction
    
    function UpdateTitle()
            normal m'
            execute '/* Last modified\s*:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@'
            normal "
            normal mk
            execute '/* Filename\s*:/s@:.*$@\=": ".expand("%:t")@'
            execute "noh"
            normal 'k
            echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
    endfunction
    
    function AddTitle()
            call append(0,"#!/bin/bash")
            call append(1,"#==========================================================")
            call append(2,"# Author        : caoshibo")
            call append(3,"# Email         : shibo.cao@foxmail.com")
            call append(4,"# Last modified : ".strftime("%Y-%m-%d %H:%M"))
            call append(5,"# Filename      : ".expand("%:t"))
            call append(6,"# Description   : You know what i mean,hehe")
            call append(7,"#==========================================================")
            echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
    endfunction
    

    试验
    vi b.sh F4

    heihei

    相关文章

      网友评论

          本文标题:vi一键添加脚本信息

          本文链接:https://www.haomeiwen.com/subject/zxndvxtx.html