<?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>Some reminiscences, some memories &#187; vim</title>
	<atom:link href="http://www.mikespook.com/index.php/tag/vim/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mikespook.com</link>
	<description>Just another boring day</description>
	<lastBuildDate>Tue, 10 Jan 2012 03:14:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>一个设置 golang 的 vim 开发环境的脚本</title>
		<link>http://www.mikespook.com/2011/09/%e4%b8%80%e4%b8%aa%e8%ae%be%e7%bd%ae-golang-%e7%9a%84-vim-%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e7%9a%84%e8%84%9a%e6%9c%ac/</link>
		<comments>http://www.mikespook.com/2011/09/%e4%b8%80%e4%b8%aa%e8%ae%be%e7%bd%ae-golang-%e7%9a%84-vim-%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e7%9a%84%e8%84%9a%e6%9c%ac/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 15:07:25 +0000</pubDate>
		<dc:creator>mikespook</dc:creator>
				<category><![CDATA[Golang]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[gocode]]></category>
		<category><![CDATA[golang]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.mikespook.com/?p=1102</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
golang 本身在代码的 misc/vim 中提供了相应脚本，用来集成 golang 的 vim 环境。而第三方项目 gocode 则更是一个强大的工具。我在《gocode——VIM 和 Emacs 的 golang 代码自动补全》中已经介绍过了。

这两个项目都很活跃，而社区活跃带来的最大麻烦就是频繁更新。为了能方便的升级 vim 环境的 golang 脚本，所以写了这个 shell。

可以 step by step 的协助集成 golang 相关脚本到 vim 中。

<span class="readmore"><a href="http://www.mikespook.com/2011/09/%e4%b8%80%e4%b8%aa%e8%ae%be%e7%bd%ae-golang-%e7%9a%84-vim-%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e7%9a%84%e8%84%9a%e6%9c%ac/" title="一个设置 golang 的 vim 开发环境的脚本">阅读全文——共413字</a></span>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>golang 本身在代码的 <a href="http://code.google.com/p/go/source/browse/#hg%2Fmisc%2Fvim" target="_blank">misc/vim</a> 中提供了相应脚本，用来集成 golang 的 vim 环境。而第三方项目 <a href="https://github.com/nsf/gocode" target="_blank">gocode</a> 则更是一个强大的工具。我在《<a href="http://www.mikespook.com/2011/03/gocode%e2%80%94%e2%80%94vim-%e5%92%8c-emacs-%e7%9a%84-golang-%e4%bb%a3%e7%a0%81%e8%87%aa%e5%8a%a8%e8%a1%a5%e5%85%a8/" target="_blank">gocode——VIM 和 Emacs 的 golang 代码自动补全</a>》中已经介绍过了。</p>
<p>这两个项目都很活跃，而社区活跃带来的最大麻烦就是频繁更新。为了能方便的升级 vim 环境的 golang 脚本，所以写了这个 shell。</p>
<p>可以 step by step 的协助集成 golang 相关脚本到 vim 中。</p>
<p>下载地址：<a href="https://bitbucket.org/mikespook/learning_go_chinese/downloads/vim.sh" target="_blank">https://bitbucket.org/mikespook/learning_go_chinese/downloads/vim.sh</a>。</p>
<p>虽然脚本会检测相关环境变量和依赖程序，不过还是最好提前设置好，免得麻烦。当然也可以将脚本到某个目录，让脚本自动下载 go 代码和 gocode 代码。</p>
<p>现在唯一没在这个脚本中集成的就是环境变量的设置和 .vimrc 中关于 syntax 之类的通用设置的开启。这些内容，DIY吧。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikespook.com/2011/09/%e4%b8%80%e4%b8%aa%e8%ae%be%e7%bd%ae-golang-%e7%9a%84-vim-%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e7%9a%84%e8%84%9a%e6%9c%ac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gocode——VIM 和 Emacs 的 golang 代码自动补全</title>
		<link>http://www.mikespook.com/2011/03/gocode%e2%80%94%e2%80%94vim-%e5%92%8c-emacs-%e7%9a%84-golang-%e4%bb%a3%e7%a0%81%e8%87%aa%e5%8a%a8%e8%a1%a5%e5%85%a8/</link>
		<comments>http://www.mikespook.com/2011/03/gocode%e2%80%94%e2%80%94vim-%e5%92%8c-emacs-%e7%9a%84-golang-%e4%bb%a3%e7%a0%81%e8%87%aa%e5%8a%a8%e8%a1%a5%e5%85%a8/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 03:33:00 +0000</pubDate>
		<dc:creator>mikespook</dc:creator>
				<category><![CDATA[Stardy & Research]]></category>
		<category><![CDATA[autocompletion]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[gocode]]></category>
		<category><![CDATA[golang]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.mikespook.com/?p=908</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
虽然 golang 自身提供了 VIM 的语法高亮之类的脚本，但 autocompletion 并没有官方解决方案。无意之中发现 gocode 这个支持 VIM 和 Emacs 的 autocompletion daemon。

这里有个Flash 动画演示，展示了 gocode 的强大。我得说，用过之后，感觉速度确实够快。

下面是来自官方的部分介绍：

<span class="readmore"><a href="http://www.mikespook.com/2011/03/gocode%e2%80%94%e2%80%94vim-%e5%92%8c-emacs-%e7%9a%84-golang-%e4%bb%a3%e7%a0%81%e8%87%aa%e5%8a%a8%e8%a1%a5%e5%85%a8/" title="gocode——VIM 和 Emacs 的 golang 代码自动补全">阅读全文——共2704字</a></span>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p><a href="http://www.mikespook.com/wp-content/uploads/2011/03/gocode.png"><img class="size-medium wp-image-909 alignright" title="gocode" src="http://www.mikespook.com/wp-content/uploads/2011/03/gocode-300x141.png" alt="" width="300" height="141" /></a>虽然 golang 自身提供了 VIM 的语法高亮之类的脚本，但 autocompletion 并没有官方解决方案。无意之中发现 <a href="https://github.com/nsf/gocode" target="_blank">gocode</a> 这个支持 VIM 和 Emacs 的 autocompletion daemon。</p>
<p>这里有个<a href="http://nsf.110mb.com/gocode-demo.swf">Flash 动画演示</a>，展示了 gocode 的强大。我得说，用过之后，感觉速度确实够快。</p>
<p>下面是来自官方的部分介绍：</p>
<p><span id="more-908"></span></p>
<blockquote><p><strong>用于 Go 编程语言的自动补全守护进程</strong></p>
<p>Gocode 是可以整合在如 vim 和 emacs 这样的代码编辑器中的辅助工具。它提供了一系列的高级功能，包括：</p>
<ul>
<li>上下文敏感的自动补全</li>
</ul>
<p>（译注：残念，还真是“一”系列啊！好吧，但是说实话单就这一个功能就很好用了。）</p>
<p>由于使用 client/server 架构的缓存形式，所以被称为守护进程。这使得自动补全非常快。通常，在缓存生效的情况下自动补全时间在 30ms，一般不会察觉这个延迟。</p></blockquote>
<p>gocode 的文档对安装说得很是详细，我这里仅对 VIM 做个简单的说明。另外，由于 golang 的 pkg 还不够稳定，不同版本可能会出现编译错误。实际上在我安装过程中，还是 fix 了 gocode 的兼容问题，才顺利安装的。下面会做详细说明。</p>
<p>首先，我假设你已经安装好了 go，设置好了 $GOBIN，并将其加入了 $PATH中。使用 8g -V 查看 go 版本，确保版本是【8g version weekly.2011-03-15 7807】。版本不同，在一些 go 的 pkg 的命名、方法等都会有不同。这可能会引起你在编译 gocode 时报错。</p>
<p>从 github 上获取 gocode 代码：</p>
<pre class="brush: bash; title: ; notranslate">git clone git://github.com/nsf/gocode.git</pre>
<p>进入 gocode 目录，编译并安装：</p>
<pre class="brush: bash; title: ; notranslate">cd gocode&amp;make install</pre>
<p>在我的编译过程中，出现如下错误：</p>
<pre class="brush: bash; title: ; notranslate">
mikespook@mikespook-desktop:~/Desktop/gocode$ make install
8g -o _go_.8 gocode.go autocompletefile.go package.go autocompletecontext.go server.go rpc.go decl.go apropos.go scope.go ripper.go config.go declcache.go os_posix.go
autocompletefile.go:230: undefined: ast.TypeCaseClause
autocompletefile.go:232: undefined: ast.TypeCaseClause
autocompletefile.go:246: typechecking loop
make: *** [_go_.8] 错误 1
</pre>
<p>这是由于 go/ast 中的 TypeCaseClause 已经改名为 CaseClause。用下面的 patch 即可解决这个问题：</p>
<pre class="brush: diff; title: ; notranslate">
diff --git a/autocompletefile.go b/autocompletefile.go
index e08e161..c0c83c4 100644
--- a/autocompletefile.go
+++ b/autocompletefile.go
@@ -227,17 +227,17 @@ func (f *AutoCompleteFile) processTypeSwitchStmt(a *ast.TypeSwitchStmt) {
                }
        }

-       var lastCursorAfter *ast.TypeCaseClause
+       var lastCursorAfter *ast.CaseClause
        for _, s := range a.Body.List {
-               if cc := s.(*ast.TypeCaseClause); f.cursor &gt; f.fset.Position(cc.Colon).Offset {
+               if cc := s.(*ast.CaseClause); f.cursor &gt; f.fset.Position(cc.Colon).Offset {
                        lastCursorAfter = cc
                }
        }

        if lastCursorAfter != nil {
                if tv != nil {
-                       if lastCursorAfter.Types != nil &amp;&amp; len(lastCursorAfter.Types) == 1 {
-                               tv.Type = lastCursorAfter.Types[0]
+                       if lastCursorAfter.List != nil &amp;&amp; len(lastCursorAfter.List) == 1 {
+                               tv.Type = lastCursorAfter.List[0]
                                tv.Value = nil
                        }
                        f.scope.addNamedDecl(tv)
</pre>
<p>完成后，安装程序会自动将编译好的 gocode 可执行文件复制到 $GOBIN 目录中。所以请务必确保 $GOBIN 设置正确。</p>
<p>对于 VIM 来说：</p>
<p>首先确保 $GOROOT/misc/vim 中的 Go VIM 脚本正确安装配置。可参考我的 vim 配置：<a href="https://bitbucket.org/mikespook/foobar/src/b7dbcbdbf3dd/vim/" target="_blank">https://bitbucket.org/mikespook/foobar/src/b7dbcbdbf3dd/vim/</a></p>
<p>然后安装 gocode 的 vim 脚本，可以简单执行 gocode 提供的 shell 脚本：</p>
<pre class="brush: bash; title: ; notranslate">cd gocode/vim &amp;&amp; ./update.bash</pre>
<p>实际上，这个脚本做了以下工作：</p>
<pre class="brush: bash; title: ; notranslate">
#!/usr/bin/env bash
mkdir -p ~/.vim/{autoload,ftplugin}
cp autoload/gocomplete.vim ~/.vim/autoload
cp ftplugin/go.vim ~/.vim/ftplugin
</pre>
<p>确保 vim 启用了 filetype 插件，.vimrc 中应当有：</p>
<pre class="brush: bash; title: ; notranslate">filetype plugin on</pre>
<p>好了，用 <C-x><C-o> 现在可以呼出 go 语言的自动补全了。</p>
<p>我为了方便，将 Ctrl+Space 映射为自动补全快捷键：</p>
<pre class="brush: bash; title: ; notranslate">imap &lt;C-Space&gt; &lt;C-x&gt;&lt;C-o&gt;</pre>
<p>由于我不用 Emacs，所以 Emacs 党请绕道官方文档吧……;)</p>
<p>【最新更新】</p>
<p>根据作者提供的线索，使用 golang 的 weekly 版本是不需要打补丁的。所以，正确的 golang 安装版本是【3b4e9c85b643 weekly/weekly.2011-03-15】</p>
<pre class="brush: bash; title: ; notranslate">
hg up -r weekly
hg id
</pre>
<p>在 7787 版本 CaseClause 才与 TypeCaseClause 合并到一起，成为 CaseClause。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikespook.com/2011/03/gocode%e2%80%94%e2%80%94vim-%e5%92%8c-emacs-%e7%9a%84-golang-%e4%bb%a3%e7%a0%81%e8%87%aa%e5%8a%a8%e8%a1%a5%e5%85%a8/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Netbeans 6 下使用 vim 的插件</title>
		<link>http://www.mikespook.com/2008/04/netbeans-6-%e4%b8%8b%e4%bd%bf%e7%94%a8-vim-%e7%9a%84%e6%8f%92%e4%bb%b6/</link>
		<comments>http://www.mikespook.com/2008/04/netbeans-6-%e4%b8%8b%e4%bd%bf%e7%94%a8-vim-%e7%9a%84%e6%8f%92%e4%bb%b6/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 06:37:20 +0000</pubDate>
		<dc:creator>mikespook</dc:creator>
				<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[viex]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.mikespook.com/?p=118</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
在厭倦了來回切換 gvim 和 netbeans，以及無數次向代碼中插入冒號之后，決定為 Netbeans 安裝一個 vim 插件。externaleditor 已經過分古舊。大概是對自己的編輯器很有信心吧, 官方沒有提供 6.0 的編輯器擴展方式。

在 sf 上找到了這個東東——VIEX，還可以，就像它介紹的那樣“Is not very good, but useful”。

不過遺憾的是，好像并不是直接內嵌 vim 到 netbeans。而是模擬了 vim 的使用方式。所以總有些用著不合適的地方。不過不管怎么說 :w 能存盤了。

]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>在厭倦了來回切換 gvim 和 netbeans，以及無數次向代碼中插入冒號之后，決定為 Netbeans 安裝一個 vim 插件。externaleditor 已經過分古舊。大概是對自己的編輯器很有信心吧, 官方沒有提供 6.0 的編輯器擴展方式。</p>
<p>在 <a href="http://www.sf.net" target="_blank">sf</a> 上找到了這個東東——<a href="http://viex.sourceforge.net/" target="_blank">VIEX</a>，還可以，就像它介紹的那樣“Is not very good, but useful”。</p>
<p>不過遺憾的是，好像并不是直接內嵌 vim 到 netbeans。而是模擬了 vim 的使用方式。所以總有些用著不合適的地方。不過不管怎么說 :w 能存盤了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikespook.com/2008/04/netbeans-6-%e4%b8%8b%e4%bd%bf%e7%94%a8-vim-%e7%9a%84%e6%8f%92%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

