Writing shell scripts to automatically generate start of the comment Profile

Often write some comments in the shell in the edit sh script, a gradient method described today, can automatically generate automatic comments briefings and other information in the shell in a shell script vim each time.

It will come automatically generate some comments to share the following information when a shell script template file, copy it to the user's home directory and named as .vimrc name, so that in future we open the file in .sh end again, just a little As shown in FIG change it to:

Writing shell scripts to automatically generate start of the comment Profile

Is not it convenient? Here to share with you the code, and then according to their needs paste the following into the file and make changes according to their own requirements, save and exit it.

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,"#Author: Linuxidc.com")
 call setline(4,"#Linux公社: www.linuxidc.com")
 call setline(5,"#Date: ".strftime("%Y-%m-%d"))
 call setline(6,"#FileName: ".expand("%")) 
 call setline(7,"#URL: https://www.linuxidc.com/Linux/2019-06/158912.htm")
 call setline(8,"#Description: Annotated script")
 call setline(9,"#********************************************************************")
 call setline(10,"")
endif
endfunc
autocmd BufNewFile * normal G

Automatic writing shell scripts to automatically generate start of the comment Profile

You finish editing the discovery, ls not view this file, because it becomes a hidden file, ll -a you can view the

However, you can edit the shell vim files, it is not very practical.

Guess you like

Origin www.linuxidc.com/Linux/2019-06/158912.htm