<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>孙立文的博客 &#187; VIM</title>
	<atom:link href="http://sunliwen.com/tag/vim/feed/" rel="self" type="application/rss+xml" />
	<link>http://sunliwen.com</link>
	<description>Never lose my passion!</description>
	<lastBuildDate>Sat, 21 Jan 2012 05:16:52 +0000</lastBuildDate>
	<language>zh</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>通过RopeVIM在VIM中实现Python自动完成</title>
		<link>http://sunliwen.com/2009/12/ropevim-rope-in-vim/</link>
		<comments>http://sunliwen.com/2009/12/ropevim-rope-in-vim/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 18:45:13 +0000</pubDate>
		<dc:creator>Liwen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[VIM]]></category>

		<guid isPermaLink="false">http://thinklouder.cn/?p=1044</guid>
		<description><![CDATA[ropevim可以实现在vim中自动完成，自动import等功能。 参考: http://rope.sourceforge.net/ropevim.html 下载几个rope，ropevim，ropemode： mkdir ~/install/ropehg hg clone http://bitbucket.org/agr/rope/ ~/install/ropehg/rope hg clone http://bitbucket.org/agr/ropevim/ ~/install/ropehg/ropevim hg clone http://bitbucket.org/agr/ropemode/ ~/install/ropehg/ropemode 可以选择安装： cd ~/install/ropehg/rope python setup.py install cd ~/install/ropehg/ropevim python setup.py install cd ~/install/ropehg/ropemode python setup.py install 或者在 .vimrc 中添加下面的代码: let $PYTHONPATH .= &#34;:/Users/liwen/install/ropehg/rope:/Users/liwen/install/ropehg/ropemode:/Users/liwen/install/ropehg/ropevim&#34; source /Users/liwen/install/ropehg/ropevim/ropevim.vim 配置ropevim的代码如下 let ropevim_codeassist_maxfixes=10 let ropevim_guess_project=1 let ropevim_vim_completion=1 let ropevim_enable_autoimport=1 let ropevim_extended_complete=1 &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>ropevim可以实现在vim中自动完成，自动import等功能。<br />
参考: <a href="http://rope.sourceforge.net/ropevim.html">http://rope.sourceforge.net/ropevim.html</a></p>
<p>下载几个rope，ropevim，ropemode：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>ropehg
hg clone http:<span style="color: #000000; font-weight: bold;">//</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>agr<span style="color: #000000; font-weight: bold;">/</span>rope<span style="color: #000000; font-weight: bold;">/</span> ~<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>ropehg<span style="color: #000000; font-weight: bold;">/</span>rope
hg clone http:<span style="color: #000000; font-weight: bold;">//</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>agr<span style="color: #000000; font-weight: bold;">/</span>ropevim<span style="color: #000000; font-weight: bold;">/</span> ~<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>ropehg<span style="color: #000000; font-weight: bold;">/</span>ropevim
hg clone http:<span style="color: #000000; font-weight: bold;">//</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>agr<span style="color: #000000; font-weight: bold;">/</span>ropemode<span style="color: #000000; font-weight: bold;">/</span> ~<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>ropehg<span style="color: #000000; font-weight: bold;">/</span>ropemode</pre></div></div>

<p>可以选择安装：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>ropehg<span style="color: #000000; font-weight: bold;">/</span>rope  
python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>ropehg<span style="color: #000000; font-weight: bold;">/</span>ropevim  
python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>ropehg<span style="color: #000000; font-weight: bold;">/</span>ropemode  
python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>或者在 .vimrc 中添加下面的代码:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">let</span> <span style="color: #000000;">$</span>PYTHONPATH <span style="color: #000000;">.</span>= <span style="color: #C5A22D;">&quot;:/Users/liwen/install/ropehg/rope:/Users/liwen/install/ropehg/ropemode:/Users/liwen/install/ropehg/ropevim&quot;</span>
source <span style="color: #000000;">/</span>Users<span style="color: #000000;">/</span>liwen<span style="color: #000000;">/</span>install<span style="color: #000000;">/</span>ropehg<span style="color: #000000;">/</span>ropevim<span style="color: #000000;">/</span>ropevim<span style="color: #000000;">.</span>vim</pre></div></div>

<p>配置ropevim的代码如下</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">let</span> ropevim_codeassist_maxfixes=<span style="color: #000000; font-weight:bold;">10</span>
<span style="color: #804040;">let</span> ropevim_guess_project=<span style="color: #000000; font-weight:bold;">1</span>
<span style="color: #804040;">let</span> ropevim_vim_completion=<span style="color: #000000; font-weight:bold;">1</span>
<span style="color: #804040;">let</span> ropevim_enable_autoimport=<span style="color: #000000; font-weight:bold;">1</span>
<span style="color: #804040;">let</span> ropevim_extended_complete=<span style="color: #000000; font-weight:bold;">1</span>
&nbsp;
<span style="color: #804040;">function</span><span style="color: #000000;">!</span> CustomCodeAssistInsertMode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #804040;">call</span> RopeCodeAssistInsertMode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #804040;">if</span> <span style="color: #25BB4D;">pumvisible</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #804040;">return</span> <span style="color: #C5A22D;">&quot;<span style="">\&lt;</span>C-L&gt;<span style="">\&lt;</span>Down&gt;&quot;</span>
    <span style="color: #804040;">else</span>
        <span style="color: #804040;">return</span> <span style="color: #C5A22D;">''</span>
    <span style="color: #804040;">endif</span>
endfunction
&nbsp;
<span style="color: #804040;">function</span><span style="color: #000000;">!</span> TabWrapperComplete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #804040;">let</span> cursyn = <span style="color: #25BB4D;">synID</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'.'</span><span style="color: #000000;">&#41;</span>, <span style="color: #25BB4D;">col</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'.'</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">-</span> <span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>
    <span style="color: #804040;">if</span> <span style="color: #25BB4D;">pumvisible</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #804040;">return</span> <span style="color: #C5A22D;">&quot;<span style="">\&lt;</span>C-Y&gt;&quot;</span>
    <span style="color: #804040;">endif</span>
    <span style="color: #804040;">if</span> <span style="color: #25BB4D;">strpart</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">getline</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'.'</span><span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #25BB4D;">col</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'.'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> =<span style="color: #000000;">~</span> <span style="color: #C5A22D;">'^<span style="">\s</span>*$'</span> <span style="color: #000000;">||</span> cursyn <span style="color: #000000;">!</span>= <span style="color: #000000; font-weight:bold;">0</span>
        <span style="color: #804040;">return</span> <span style="color: #C5A22D;">&quot;<span style="">\&lt;</span>Tab&gt;&quot;</span>
    <span style="color: #804040;">else</span>
        <span style="color: #804040;">return</span> <span style="color: #C5A22D;">&quot;<span style="">\&lt;</span>C-R&gt;=CustomCodeAssistInsertMode()<span style="">\&lt;</span>CR&gt;&quot;</span>
    <span style="color: #804040;">endif</span>
endfunction
&nbsp;
inoremap <span style="color: #000000;">&lt;</span>buffer<span style="color: #000000;">&gt;&lt;</span>silent<span style="color: #000000;">&gt;&lt;</span>expr<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>Tab<span style="color: #000000;">&gt;</span> TabWrapperComplete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>自动完成直接可以用，但 RopeRename 不工作，可能是工程太大，分起来比较费劲。还不错。 </p>
<p>PS:<br />
1. hg &#8211; <a href="http://mercurial.selenic.com/">mercurial</a><br />
2. 如果遇到以下错误</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">Error detected while processing function LoadRope:
line    1:
E319: Sorry, the command is not available in this version: python &lt;&lt; EOF
line    2:
E492: Not an editor command: import ropevim
line    3:
E492: Not an editor command: EOF
Press ENTER or type command to continue</pre></div></div>

<p>可能由于vim没有启用python支持，可以打开一个buffer，在命令模式下输入</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>python print <span style="color: #C5A22D;">&quot;hello&quot;</span></pre></div></div>

<p>如能正常打印，则配置正确，否则需要重新编译或者安装python支持</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">sudo port install vim +python26
sudo port install mvim +python26</pre></div></div>

<p>Good luck!!</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="ckepop">
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_douban"></a>
	<a class="jiathis_button_instapaper"></a>
	<a class="jiathis_button_stubleupon"></a>
	<a href="http://www.jiathis.com/share?uid=1544311" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript">var jiathis_config = {data_track_clickback:true};</script>
<script type="text/javascript" src="http://v2.jiathis.com/code_mini/jia.js?uid=1544311" charset="utf-8"></script>
<!-- JiaThis Button END --></div><hr />
<p>
<small>
Tags: <a href="http://sunliwen.com/tag/python/" rel="tag">Python</a>, <a href="http://sunliwen.com/tag/vim/" rel="tag">VIM</a><br/>
<a href="http://sunliwen.com/2009/12/ropevim-rope-in-vim/#comments-heading">2个评论</a>
</small>
</p>]]></content:encoded>
			<wfw:commentRss>http://sunliwen.com/2009/12/ropevim-rope-in-vim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

