使用vimplus创建文件时自动添加信息和创建时间

安装vimplus参考

http://www.cnblogs.com/highway-9/p/5984285.html?spm=a2c4e.11153940.blogcont75530.9.39142637RWOmhw

在已经完成vimplus的安装后

在vimplus中预定义的编码脚本放在~/.vim/plugged/prepare-code/prepare/autoload

在prepare.vim中插入这个函数,参考的是下面的博文

https://blog.csdn.net/amoscykl/article/details/80616688

" 生成作者信息
function! s:gen_information(suffix)
    if a:suffix == 'sh' || a:suffix == 'py'        
        call setline(1, "##########################################################################")         
        call append(line("."), "# File Name: ".expand("%"))         
        call append(line(".")+1, "# Author: Name")         
        call append(line(".")+2, "# mail: Name@qq.com")         
        call append(line(".")+3, "# Created Time: ".strftime("%c"))         
        call append(line(".")+4, "#########################################################################")         
        call append(line(".")+5, "")    
    elseif a:suffix == 'c' || a:suffix == 'cpp' || a:suffix == 'h' 
        call setline(1, "/*************************************************************************")         
        call append(line("."), "*File Name: ".expand("%"))         
        call append(line(".")+1, "*Author: Name")         
        call append(line(".")+2, "*Name@qq.com")         
        call append(line(".")+3, "*Created Time: ".strftime("%c"))         
        call append(line(".")+4, " ************************************************************************/")         
        call append(line(".")+5, "")    
    endif    
endfunction

并在主函数中添加代码

function! prepare#prepare#gen_prepare_code()
     let suffix = prepare#util#get_current_file_suffix()
     call <sid>gen_information(suffix) "生成作者信息
     call <sid>gen_prepare_code_by_suffix(suffix)
endfunction

并在util.vim中
prepare#util#write_text_at_current_row函数中
添加
execute "normal G"

function! prepare#util#write_text_at_current_row(text)
    execute "normal G"
    execute "normal i" . a:text
endfunction

这是新创建后的界面:

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值