vim在源碼中自動添加做者信息

「將鍵盤上的F4功能鍵映射爲添加做者信息的快捷鍵vim

map <F4> ms:call TitleDet()<cr>'sapp

function AddTitle()this

    call append(0,"/*******************************************************************************")spa

    "call append(1,"#")orm

    call append(1," * Author :          YuanLu")ip

    "call append(3,"#")get

    call append(2," * Email :           yuanlu837@gmail.com")it

    "call append(5,"*")io

    call append(3," * Last modified :   ".strftime("%Y-%m-%d %H:%M"))ast

    "call append(7,"#")

    call append(4," * Filename :        ".expand("%:t"))

    "call append(9,"#")

    call append(5," * Description :     ")

    ""call append(11,"#")

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

    echohl WarningMsg | echo "Successful in adding the copyright." | echohl None

endf

"更新最近修改時間和文件名

normal m'

"execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'

normal "

normal mk

"execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@'

execute "noh"

normal 'k

"echohl WarningMsg | echo "\n" | 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

這段配置在Linux和window下都可正常運行。這樣在一個C/C++/JAVA/C#的源代碼裏面,只須要按一下F4,就能夠自動添加做者信息了。你們只須要修改上面這段配置關於做者信息的代碼,就能夠添加本身的信息了。

這是在我電腦上運行的結果,看一看,是否是很帥:

趕快動手吧,把這段配置添加到你的vimrc裏,這樣你就能夠輕鬆地在源文件開始添加你的相關信息了,讓咱們的代碼更加規範。

/*!***********************************************************************

Function       OutputInfo

description    When prefOutputInfo is set to true this function outputs

various pieces of non-API dependent information via

PVRShellOutputDebug.

*************************************************************************/

相關文章
相關標籤/搜索