Vim配置-新建python自动添加注释

Vim新建python,自动添加注释头信息

function GetSystemUname()
    let uname=system("whoami")
    if uname[strlen(uname) - 1] == "\n"
        let uname=strpart(uname, 0, strlen(uname) - 1)
    endif
    return uname
endf

function HeaderPython()
    let username=GetSystemUname()
    let filename=expand('%:t')
    call setline(1, "# -*- coding: utf-8 -*-")
    call setline(2, "# Author @".username)
    call setline(3, "# Description @ ".filename)
    call setline(4, "#  CreateTime @ ".strftime('%Y-%m-%d %H:%M:%S', localtime()))
    normal G
    normal o
    normal o
endf

autocmd BufNewFile *.py call HeaderPython()

你可能感兴趣的:(Vim配置-新建python自动添加注释)