vim - 如何查看特定 go 函数的文档?

标签 vim go

我正在寻找一种方便的方法来快速查找 Go 中不同函数和/或包的文档。我目前的方法是用谷歌搜索 ioutil.ReadFile,但这很慢/很不方便。 理想的解决方案将直接在 vim 中工作,或者可能在 Go 解释器中工作(建议?)。

例如在 Python 中,函数的文档可以通过将鼠标悬停在函数上或使用 ipython 解释器在 PyDev 中显示,例如os.open?help(os.open)

您如何查看 Go 的特定文档?

最佳答案

你有很多可能性:

  • 浏览 http://golang.org/pkg/和/或使用甚至知道正则表达式的“搜索”框!
  • 运行本地 godoc 并为所有本地安装的包获取相同的文件。更快和离线!
  • 从命令行查询 godoc:

$ godoc io/ioutil ReadFile
PACKAGE DOCUMENTATION

package ioutil
    import "io/ioutil"



FUNCTIONS

func ReadFile(filename string) ([]byte, error)
    ReadFile reads the file named by filename and returns the contents. A
    successful call returns err == nil, not err == EOF. Because ReadFile
    reads the whole file, it does not treat an EOF from Read as an error to
    be reported.


$ 

  • 使用 Rob Pike 的 doc[0]。

$ doc ioutil.ReadFile
http://golang.org/pkg/io/ioutil/#ReadFile
/home/jnml/go/src/pkg/io/ioutil/ioutil.go:48:
// ReadFile reads the file named by filename and returns the contents.
// A successful call returns err == nil, not err == EOF. Because ReadFile
// reads the whole file, it does not treat an EOF from Read as an error
// to be reported.
func ReadFile(filename string) ([]byte, error)

$ 

[0]: $ go get code.google.com/p/rspace.cmd/doc

关于vim - 如何查看特定 go 函数的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17945068/

相关文章:

VIM 拼写检查,带引号的字符串 - PHP

windows - 如何在 gVim (Win32) 中缩进选择

git - 多个 Vagrant 盒的最佳实践

delphi - 第 3 方 dll 中未处理的 delphi 异常

vim - 将 sudo 与 .vimrc 结合使用

vim 键映射引用

go - 如何构建 thrift4go?

go - 为什么我在 Go 中获取不到类型转换的地址?

oop - 为什么go语言的方法有奇怪的语法

sql - 从 SQL 查询中获取表名