Linux中shell脚本设置开头固定格式方法(Linux脚本文件中怎么打字)
admin2024-08-14 10:14:45Linux运维
编辑vim ~/.vimrc
放入以下内容,保存即可。
set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"################# Version Info ##################")
call setline(3,"# Create Date: ".strftime("%Y-%m-%d"))
call setline(4,"# Author: shnne")
call setline(5,"# Mail: postmaster@shnne.com")
call setline(6,"# Filename: ".expand("%"))
call setline(7,"# Url: https://www.shnne.com")
call setline(8,"# Description: The shnne script")
call setline(9,"#################################################")
call setline(10,"")
endif
endfunc
autocmd BufNewFile * normal G
创建test.sh查看是否成功
其他格式
set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"#")
call setline(3,"#--------------------------------------------------------------")
call setline(4,"# AUTHOR: shnne")
call setline(5,"# EMAIL: postmaster@shnne.com")
call setline(6,"# DATE: ".strftime("%Y-%m-%d"))
call setline(7,"# FILENAME: ".expand("%"))
call setline(8,"# URL: https://www.shnne.com")
call setline(9,"# DESCRIPTION: The shnne script")
call setline(10,"# Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(11,"#--------------------------------------------------------------")
call setline(12,"")
endif
endfunc
autocmd BufNewFile * normal G