<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="http://blog.xole.net/rss/style.css" type="text/css"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:content="http://purl.org/rss/1.0/modules/content/"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xml:lang="ja">
<channel rdf:about="http://blog.xole.net/rss/1.0.php?id=396">
<title>ハタさんのブログ(復刻版)</title>
<link>http://blog.xole.net/index.php</link>
<dc:date>2006-01-30T03:02:29+09:00</dc:date>
<description>
ハタさんのブログ(復刻版) - RSS (RDF Site Summary).
</description>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://blog.xole.net/article.php?id=396" />
</rdf:Seq>
</items>
</channel>
<item>
<title>vimスクリプトとか書いてみた。</title>
<link>http://blog.xole.net/article.php?id=396</link>
<dc:date>2006-01-30T03:02:29+09:00</dc:date>
<description>
Comfortable PHP editing with VIM -3-で紹介されてる .vimrcはなかなかいい感じだったりするわけで、
vim上での TAB 補完をしてくれるんだけど、map! がどうも気に入らないわけです。
同じ...</description>
<content:encoded>
<![CDATA[
<p>
<a href="http://www.schlitt.info/applications/blog/index.php?/archives/331-Comfortable-PHP-editing-with-VIM-3.html" title="Comfortable PHP editing with VIM -3- - Tobias Schlitt - a passion for php">Comfortable PHP editing with VIM -3-</a>で紹介されてる <a href="http://www.schlitt.info/misc/.vimrc">.vimrc</a>はなかなかいい感じだったりするわけで、
vim上での <kbd>TAB</kbd> 補完をしてくれるんだけど、map! がどうも気に入らないわけです。<br />
同じような文字列が沢山あるし、何より @since とか@author に補完してくれない。(php-doc.vim使えってわけですが...)</p>

<p>なので、基本は同じでちょっと作り替えたよ！</p>

<pre>
<code>set formatoptions=qroct
let g:date = strftime("%Y/%m/%d")
let g:author = "nowel"

imap &lt;C-o&gt; ^[:set paste&lt;CR&gt;:exe PhpDoc()&lt;CR&gt;:set nopaste&lt;CR&gt;i
map! =cls &lt;ESC&gt;:call InsertClassDoc()&lt;CR&gt;
map! =req &lt;ESC&gt;:call InsertRequireDoc(0, 0)&lt;CR&gt;
map! =reo &lt;ESC&gt;:call InsertRequireDoc(0, 1)&lt;CR&gt;
map! =inc &lt;ESC&gt;:call InsertRequireDoc(1, 0)&lt;CR&gt;
map! =ioc &lt;ESC&gt;:call InserRequireDoc(1, 1)&lt;CR&gt;
map! =pubf &lt;ESC&gt;:call InsertMethodDoc(0)&lt;CR&gt;
map! =prof &lt;ESC&gt;:call InsertMethodDoc(1)&lt;CR&gt;
map! =prif &lt;ESC&gt;:call InsertMethodDoc(2)&lt;CR&gt;
map! =pubp &lt;ESC&gt;:call InsertPropertyDoc(0)&lt;CR&gt;
map! =prop &lt;ESC&gt;:call InsertPropertyDoc(1)&lt;CR&gt;
map! =prip &lt;ESC&gt;:call InsertPropertyDoc(2)&lt;CR&gt;
noremap ; :!php -l %&lt;CR&gt;
noremap &lt;C-l&gt; :w!&lt;CR&gt;:!php %&lt;CR&gt;

function! InsertClassDoc()
    execute "normal i/**\&lt;CR&gt;\&lt;CR&gt;@author " . g:author . "\&lt;CR&gt;@since " .  g:date . "\&lt;CR&gt;/\&lt;CR&gt;class  {\&lt;CR&gt;\&lt;CR&gt;}\&lt;ESC&gt;?/\*/*\&lt;CR&gt;/ \* \&lt;CR&gt;$i"
endfunction

function! InsertMethodDoc(access)
    let s:head = "/**\&lt;CR&gt;\&lt;CR&gt;@since " . g:date . "\&lt;CR&gt;"
    "pubf: public function
    if a:access == 0
        let s:body = "@access public\&lt;CR&gt;@param\&lt;CR&gt;@return void\&lt;CR&gt;/\&lt;CR&gt;public"
    endif
    "prof: protected function
    if a:access == 1
        let s:body = "@access protected\&lt;CR&gt;@param\&lt;CR&gt;@return void\&lt;CR&gt;/\&lt;CR&gt;protected"
    endif
    "prif: private function
    if a:access == 2
        let s:body = "@access private\&lt;CR&gt;@param\&lt;CR&gt;@return void\&lt;CR&gt;/\&lt;CR&gt;private"
    endif
    let s:foot = " function func () {\&lt;CR&gt;\&lt;CR&gt;}\&lt;CR&gt;\&lt;ESC&gt;?/\*/*\&lt;CR&gt; \* \&lt;CR&gt;$i"
    execute "normal i" . s:head . s:body . s:foot
endfunction

function! InsertPropertyDoc(access)
    let s:head = "/**\&lt;CR&gt;\&lt;CR&gt;@var \&lt;CR&gt;@since " . g:date . "\&lt;CR&gt;/\&lt;CR&gt;"
    "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 = "\&lt;ESC&gt;?/\*/*\&lt;CR&gt;/ \* \&lt;CR&gt;$i"
    execute "normal i" . s:head . s:body . s:foot
endfunction

function! InsertRequireDoc(require, once)
    let s:head = "/**\&lt;CR&gt;\&lt;CR&gt;@since " . g:date . "\&lt;CR&gt;/\&lt;CR&gt;"
    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 . "\&lt;ESC&gt;"
endfunction</code>
</pre>

<p>動かし方は（mapから呼ぶだけだけど...)<br />
挿入時に <kbd>=cls</kbd> とかって入力するだけ</p>

<p>こんなのが、簡単に作れるよ</p>

<pre>
<code>/**
 *
 * @author nowel
 * @since 2006/01/30
 */
class  {

    /**
     *
     * @since 2006/01/30
     * @access protected
     * @param
     * @return void
     */
    protected function func () {

    }

}</code>
</pre>

<p>また、これが人生初のvimスクリプト！(スクリプトとは呼べなさそうだけど...)<br />
ちなみに、上のは <code>set formatoptions=qroct</code>が肝！<br />
あとは、autoindent とか smartindent とか入れてるかどうか。かな...<br />
インデント綺麗にできないっす。どうにかする方法教えて ＞＜；</p>

<p>ってか これ map 多すぎ　＞＜；</p>
]]>
</content:encoded>
</item>

</rdf:RDF>