linux系统下shell和python对运维人员来说是两块如虎添翼的工具,编辑shell和python就成了一条必过的桥,每次写脚本都需要写注释信息,本着对重复性工作程序化的思路,就有了本文的由来。在上篇中介绍了《Vim升级和配置》,知识讲求连贯性,本文的介绍就以vim作为主角展开。
2、环境项目
版本
CentOS Linux release 7.9.2009 (Core)
VIM - Vi IMproved 8.2
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



