# Shell脚本自动生成开头注释简介

在编辑sh脚本的时候经常会在shell里面写一些注释，今天介绍一个渐变的方法，可以在每次vim一个shell脚本的时候都会自动在shell里面自动生成注释简介等信息。

下面给大家分享一个shell脚本的模板文件，把它拷贝到用户的家目录下并命名成 .vimrc 名称，这样我们以后再次打开以 .sh结尾的文件时就会成自动生成一些注释信息，只要稍稍修改一下即可如图所示：

![](/files/h4SJK6jQRFJh8ZP6yaBc)

是不是很方便呢？ 下面给大家分享一下代码，然后根据自己的需求将下面文件粘贴进去并进行根据自己的要求更改，保存退出就可以了。

```bash
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
```

编辑完发现，ls查看不到这个文件了，这是因为它变成了一个隐藏文件，ll -a就可以查看到了

![](/files/oUVIp4AafaV8J31xIt1Q)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/centos/shell/shell-jiao-ben-zi-dong-sheng-cheng-kai-tou-zhu-shi-jian-jie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
