如何在Vim編輯器中使用鍵盤F4自動添加指令碼說明

來源:互聯網
上載者:User

在使用vim進行shell指令碼開發過程中,怎麼才能配置vim自動添加指令碼運行環境、作者、郵件、指令碼說明等資訊,網上找了些資料,最後的.vimrc設定檔貼出來。

cat ~/.vimrc

"進行著作權聲明的設定
"添加或更新頭
"將鍵盤上的F4功能鍵映射為添加作者資訊的快速鍵
map <F4> :call TitleDet()<cr>'s
function AddTitle()
call append(0,"#!/bin/sh")
call append(1,"# Filename: ".expand("%:t"))
call append(2,"# Author: zhangliang - z_liang90@126.com")
call append(3,"# QQ : 295029531")
call append(4,"# Last modified: ".strftime("%Y-%m-%d %H:%M"))
call append(5,"# Description: ")
"echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endf
"更新最近修改時間和檔案名稱
function UpdateTitle()
normal m'
execute '/# *Last modified:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/# *Filename:/s@:.*$@\=": ".expand("%:t")@'
execute "noh"
normal 'k
"echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
"判斷前10行代碼裡面,是否有Last modified這個單詞,
"如果沒有的話,代表沒有添加過作者資訊,需要新添加;
"如果有的話,那麼只需要更新即可
function TitleDet()
let n=1
"預設為添加
while n < 10
let line = getline(n)
if line =~ '^\#\s*\S*Last\smodified:\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction

儲存好後,編輯一個x.sh指令檔,按下F4鍵,這些資訊就可以自動添加了,具體的資訊自己改下就行了!

推薦閱讀:

Vim學習指南

快速學會 Vi編輯器

強大的Vim 編輯器

在CentOS 6.2上搭建Vim開發環境

Vim 7.4a 發布,全新更快的Regex引擎

CentOS 5.4 安裝高亮Vim編輯工具

Vim技巧分享:C語言設定

Ubuntu中設定Vim的行號

Vim編輯器使用基礎教程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.