zoukankan      html  css  js  c++  java
  • VIM编写shell或者python脚本时自动添加脚本开头注释信息。

             每次写脚本的时候,都要写一堆脚本的开头注释信息,时间长了自然会繁琐那我们能不能来个偷懒呢?

    偷懒的方法还是有的。那就是将下面的代码复制到~/.vimrc文件中,(放在任意位置。推荐放在末尾) ;如果没有.vimrc就新建一个。

    autocmd BufNewFile *.py,*.sh, exec ":call SetTitle()"
    let $author_name  = "zhangyong"
    let $author_email = "zhangyong@xxxxxx.com"
    
    func SetTitle()
    if &filetype == 'sh'
    call setline(1,"#!/bin/bash")
    call append(line("."),   "#File Name    : ".expand("%"))
    call append(line(".")+1, "#Author       : ".$author_name)
    call append(line(".")+2, "#Mail         : ".$author_email)
    call append(line(".")+3, "#Create Time  : ".strftime("%Y-%m-%d %H:%M"))
    call append(line(".")+4, "#Description  : ")
    call append(line(".")+5, "")
    else
    call setline(1,"#!/usr/bin/python")
    call append(line("."),   "#File Name    : ".expand("%"))
    call append(line(".")+1, "#Author       : ".$author_name)
    call append(line(".")+2, "#Mail         : ".$author_email)
    call append(line(".")+3, "#Create Time  : ".strftime("%Y-%m-%d %H:%M"))
    call append(line(".")+4, "#Description  : ")
    call append(line(".")+5, "")
    endif
    endfunc
    autocmd BufNewfile * normal G
    

    使用效果:

    shell

    python

     

     哈哈~这样每次写脚本的时候是不是方便很多呢?

     

  • 相关阅读:
    怎么往mac中finder个人收藏里添加文件夹
    UIView 动画
    添加.pch文件
    声明属性的关键字
    创建app前的环境配置/AppIcon/启动图片
    修改动画的旋转支点
    实现自定义xib和storyboard的加载,
    Quartz2D绘图 及实例:下载进度
    帧动画
    在职研究生第一单元第二单元第三单元第四单元是什么?
  • 原文地址:https://www.cnblogs.com/zyos/p/9213878.html
Copyright © 2011-2022 走看看