溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

如何編輯vim配置文件使新建文件自動(dòng)寫(xiě)入文件頭

發(fā)布時(shí)間:2021-11-06 18:35:40 來(lái)源:億速云 閱讀:180 作者:柒染 欄目:建站服務(wù)器

本篇文章為大家展示了如何編輯vim配置文件使新建文件自動(dòng)寫(xiě)入文件頭,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

因工作需要經(jīng)常寫(xiě)shell腳本,每次都要寫(xiě)腳本的頭,就想偷個(gè)懶,在每次寫(xiě)腳本的時(shí)候可以自動(dòng)生成想要的信息,編輯/etc/vimrc該文件,在新增.sh文件的時(shí)候會(huì)出現(xiàn)一些信息 

autocmd BufNewFile *.sh exec ":call Setcomment()"

func Setcomment()

        call append(0,"#!/bin/bash")

        call append(1,"#*********************************** ")

        call append(2,"#*       copyleft test " .strftime("%Y-%m-%d"))

        call append(3,"#*       scriptname: " .expand("%"))

        call append(4,"#*       email:  sb@localhost")

        call append(5,"#*       version: v0.1 ")

        call append(6,"#*********************************** ")

endfunc

=================================================================================================================================================================================================================================

編輯/etc/vimrc該文件,在新增.sh以及.py文件的時(shí)候會(huì)出現(xiàn)一些信息

autocmd BufNewFile *.py,*.sh, exec ":call SetTitle()"

let $author_name = "xxx"

let $author_email = "xxx@xxx.xxx"

func SetTitle()

if &filetype == 'sh'

        call setline(1,"\###################################################################")

        call append(line("."), "\# File Name: ".expand("%"))

        call append(line(".")+1, "\# Author: ".$author_name)

        call append(line(".")+2, "\# mail: ".$author_email)

        call append(line(".")+3, "\# Created Time: ".strftime("%c"))

        call append(line(".")+4, "\#=============================================================")

        call append(line(".")+5, "\#!/bin/bash")

        call append(line(".")+6, "")

else

        call setline(1,"\###################################################################")

        call append(line("."), "\# File Name: ".expand("%"))

        call append(line(".")+1, "\# Author: ".$author_name)

        call append(line(".")+2, "\# mail: ".$author_email)

        call append(line(".")+3, "\# Created Time: ".strftime("%c"))

        call append(line(".")+4, "\#=============================================================")

        call append(line(".")+5, "\#!/usr/bin/python")

        call append(line(".")+6, "")

endif

endfunc

上述內(nèi)容就是如何編輯vim配置文件使新建文件自動(dòng)寫(xiě)入文件頭,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

vim
AI