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

     

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

     

  • 相关阅读:
    1022. 从根到叶的二进制数之和
    剑指 Offer 54. 二叉搜索树的第k大节点
    枚举--百练2811--熄灯问题
    UVA 572 BFS 图论入门
    百练1088 DP+DFS 迷宫问题
    poj 1661 动态规划 拯救老鼠
    入坑动态规划!POJ 1458字符串最大公共子序列
    文件后缀批处理
    奇妙的算法--UVA 679(二叉树的编号)
    栈_uva514
  • 原文地址:https://www.cnblogs.com/zyos/p/9213878.html
Copyright © 2011-2022 走看看