栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

vim 配置shell和python脚本注释

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

vim 配置shell和python脚本注释

1、背景

linux系统下shell和python对运维人员来说是两块如虎添翼的工具,编辑shell和python就成了一条必过的桥,每次写脚本都需要写注释信息,本着对重复性工作程序化的思路,就有了本文的由来。在上篇中介绍了《Vim升级和配置》,知识讲求连贯性,本文的介绍就以vim作为主角展开。

2、环境

项目
版本
CentOS Linux release 7.9.2009 (Core)
VIM - Vi IMproved 8.2

3、操作

3.1、编辑配置文件
打开配置文件,新增shell和python部分。

$ vim ~/.vimrc

复制代码
在打开的文件尾部新增

""=============================================================================
" shell 和 python文件的注释
" ============================================================================
autocmd BufNewFile *.py,*.sh, exec ":call SetTitle()"
let $author_name = "shalter"
let $author_email = "shalter@xxxx.com"

function SetTitle()
    if &filetype == 'sh'
        call setline(1,"#!/bin/bash")
        call append(line("."),"# ---------------------------------------------")
        call append(line(".")+1,    "# File Name   : ".expand("%"))
        call append(line(".")+2,    "# Author      : ".$author_name)
        call append(line(".")+3,    "# Mail        : ".$author_email)
        call append(line(".")+4,    "# Date        : ".strftime('%Y-%m-%d', localtime()))
        call append(line(".")+5,    "# Description : ")
        call append(line(".")+6,    "# ---------------------------------------------")
        call append(line(".")+7,    "")
    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',localtime()))
        call append(line(".")+4,   "# Description : ")
        call append(line(".")+5,   "")

    endif
endfunc
autocmd BufNewfile * normal G


复制代码

3.2、效果图
shell

python

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/468339.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号