2006/01/30

vimスクリプトとか書いてみた。

ポスト @ 3:02:29 , 修正 @ 2006/01/30 3:17:34 | , ,     このエントリーを含むはてなブックマーク

Comfortable PHP editing with VIM -3-で紹介されてる .vimrcはなかなかいい感じだったりするわけで、 vim上での TAB 補完をしてくれるんだけど、map! がどうも気に入らないわけです。
同じような文字列が沢山あるし、何より @since とか@author に補完してくれない。(php-doc.vim使えってわけですが...)

なので、基本は同じでちょっと作り替えたよ!

set formatoptions=qroct
let g:date = strftime("%Y/%m/%d")
let g:author = "nowel"

imap <C-o> ^[:set paste<CR>:exe PhpDoc()<CR>:set nopaste<CR>i
map! =cls <ESC>:call InsertClassDoc()<CR>
map! =req <ESC>:call InsertRequireDoc(0, 0)<CR>
map! =reo <ESC>:call InsertRequireDoc(0, 1)<CR>
map! =inc <ESC>:call InsertRequireDoc(1, 0)<CR>
map! =ioc <ESC>:call InserRequireDoc(1, 1)<CR>
map! =pubf <ESC>:call InsertMethodDoc(0)<CR>
map! =prof <ESC>:call InsertMethodDoc(1)<CR>
map! =prif <ESC>:call InsertMethodDoc(2)<CR>
map! =pubp <ESC>:call InsertPropertyDoc(0)<CR>
map! =prop <ESC>:call InsertPropertyDoc(1)<CR>
map! =prip <ESC>:call InsertPropertyDoc(2)<CR>
noremap ; :!php -l %<CR>
noremap <C-l> :w!<CR>:!php %<CR>

function! InsertClassDoc()
    execute "normal i/**\<CR>\<CR>@author " . g:author . "\<CR>@since " .  g:date . "\<CR>/\<CR>class  {\<CR>\<CR>}\<ESC>?/\*/*\<CR>/ \* \<CR>$i"
endfunction

function! InsertMethodDoc(access)
    let s:head = "/**\<CR>\<CR>@since " . g:date . "\<CR>"
    "pubf: public function
    if a:access == 0
        let s:body = "@access public\<CR>@param\<CR>@return void\<CR>/\<CR>public"
    endif
    "prof: protected function
    if a:access == 1
        let s:body = "@access protected\<CR>@param\<CR>@return void\<CR>/\<CR>protected"
    endif
    "prif: private function
    if a:access == 2
        let s:body = "@access private\<CR>@param\<CR>@return void\<CR>/\<CR>private"
    endif
    let s:foot = " function func () {\<CR>\<CR>}\<CR>\<ESC>?/\*/*\<CR> \* \<CR>$i"
    execute "normal i" . s:head . s:body . s:foot
endfunction

function! InsertPropertyDoc(access)
    let s:head = "/**\<CR>\<CR>@var \<CR>@since " . g:date . "\<CR>/\<CR>"
    "pubp: public property
    if a:access == 0
        let s:body = "public $ = ;"
    endif
    "prop: protected property
    if a:access == 1
        let s:body = "protected $ = ;"
    endif
    "prip: private property
    if a:access == 2
        let s:body = "private $ = ;"
    endif
    let s:foot = "\<ESC>?/\*/*\<CR>/ \* \<CR>$i"
    execute "normal i" . s:head . s:body . s:foot
endfunction

function! InsertRequireDoc(require, once)
    let s:head = "/**\<CR>\<CR>@since " . g:date . "\<CR>/\<CR>"
    if a:require == 0
        if a:once == 0
            let s:body = s:head . "require ''\;"
        else
            let s:body = s:head . "require_once '';"
        endif
    else 
        if a:once == 0
            let s:body = s:head . "include '';"
        else
            let s:body = s:head . "include_once '';"
        endif
    endif
    execute "normal i" . s:body . "\<ESC>"
endfunction

動かし方は(mapから呼ぶだけだけど...)
挿入時に =cls とかって入力するだけ

こんなのが、簡単に作れるよ

/**
 *
 * @author nowel
 * @since 2006/01/30
 */
class  {

    /**
     *
     * @since 2006/01/30
     * @access protected
     * @param
     * @return void
     */
    protected function func () {

    }

}

また、これが人生初のvimスクリプト!(スクリプトとは呼べなさそうだけど...)
ちなみに、上のは set formatoptions=qroctが肝!
あとは、autoindent とか smartindent とか入れてるかどうか。かな...
インデント綺麗にできないっす。どうにかする方法教えて ><;

ってか これ map 多すぎ ><;


Trackback

No Trackbacks

Track from Your Website

http://blog.xole.net/trackback/tb.php?id=396

Comment

No Comments

Post Your Comment


*は入力必須です。E-Mailは公開されません。

1 + 2 =