1
0
Fork 0
mirror of synced 2024-11-26 18:55:34 -05:00
ultimate-vim/sources_non_forked/vim-go/doc/vim-go.txt

1491 lines
56 KiB
Text
Raw Normal View History

2014-10-31 17:30:24 -04:00
*vim-go.txt* Go development plugin
*vim-go*
2016-08-02 08:48:32 -04:00
==============================================================================
# #
# ## ## #### ## ## ###### ####### #
# ## ## ## ### ### ## ## ## ## #
# ## ## ## #### #### ## ## ## #
# ## ## ## ## ### ## ####### ## #### ## ## #
# ## ## ## ## ## ## ## ## ## #
# ## ## ## ## ## ## ## ## ## #
# ### #### ## ## ###### ####### #
# #
==============================================================================
CONTENTS *go-contents*
2014-10-31 17:30:24 -04:00
2016-02-20 08:13:10 -05:00
1. Intro........................................|go-intro|
2. Install......................................|go-install|
3. Commands.....................................|go-commands|
4. Mappings.....................................|go-mappings|
5. Text Objects.................................|go-text-objects|
6. Functions....................................|go-functions|
7. Settings.....................................|go-settings|
8. Troubleshooting..............................|go-troubleshooting|
9. Credits......................................|go-credits|
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
==============================================================================
INTRO *go-intro*
2014-10-31 17:30:24 -04:00
Go (golang) support for Vim. vim-go installs automatically all necessary
binaries for providing seamless Vim integration. It comes with pre-defined
sensible settings (like auto gofmt on save), has autocomplete, snippet
support, improved syntax highlighting, go toolchain commands, etc... It's
highly customizable and each individual feature can be disabled/enabled
easily.
2016-08-02 08:48:32 -04:00
* Improved Syntax highlighting with items such as Functions, Operators,
Methods.
* Auto completion support via `gocode`.
* Better `gofmt` on save, which keeps cursor position and doesn't break your
undo history.
* Go to symbol/declaration with `:GoDef`.
* Look up documentation with `:GoDoc` inside Vim or open it in browser.
* Automatically import packages via `:GoImport` or plug it into autosave.
* Compile your package with `:GoBuild`, install them with `:GoInstall` or
test them with `:GoTest` (also supports running single tests with
`:GoTestFunc`).
* Quickly execute your current file/files with `:GoRun`.
* Automatic `GOPATH` detection based on the directory structure (e.g. `gb`
projects, `godep` vendored projects).
* Change or display `GOPATH` with `:GoPath`.
2016-04-12 04:31:09 -04:00
* Create a coverage profile and display annotated source code in to see
2016-08-02 08:48:32 -04:00
which functions are covered with `:GoCoverage`.
* Call `gometalinter` with `:GoMetaLinter`, which invokes all possible
linters (golint, vet, errcheck, deadcode, etc..) and shows the
warnings/errors.
* Lint your code with `:GoLint`.
* Run your code through `:GoVet` to catch static errors.
2016-05-14 07:57:54 -04:00
* Advanced source analysis tools utilizing guru, such as `:GoImplements`,
2016-08-02 08:48:32 -04:00
`:GoCallees`, and `:GoReferrers`.
* Precise type-safe renaming of identifiers with `:GoRename`.
* List all source files and dependencies.
* Unchecked error checking with `:GoErrCheck`.
* Integrated and improved snippets, supporting `ultisnips` or `neosnippet`.
* Share your current code to [play.golang.org](http://play.golang.org) with
`:GoPlay`
2015-12-08 08:20:04 -05:00
* On-the-fly type information about the word under the cursor. Plug it into
2016-08-02 08:48:32 -04:00
your custom Vim function.
* Go asm formatting on save.
* Tagbar support to show tags of the source code in a sidebar with `gotags`.
* Custom vim text objects such as `a function` or `inner function`.
2016-02-20 08:13:10 -05:00
* A async launcher for the go command is implemented for neovim, fully async
building and testing.
* Integrated with the neovim terminal, launch `:GoRun` and other go commands
in their own new terminal.
2016-08-02 08:48:32 -04:00
* Alternate between implementation and test code with `:GoAlternate`.
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
==============================================================================
2014-10-31 17:30:24 -04:00
INSTALL *go-install*
2016-08-02 08:48:32 -04:00
Vim-go follows the standard runtime path structure, so I highly recommend to
use a common and well known plugin manager to install vim-go. Do not use
vim-go with other Go plugins. For Pathogen just clone the repo, for other
plugin managers add the appropriate lines and execute the plugin's install
command.
2014-10-31 17:30:24 -04:00
2015-03-14 16:02:10 -04:00
* https://github.com/tpope/vim-pathogen >
git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go
2014-10-31 17:30:24 -04:00
<
2015-03-14 16:02:10 -04:00
* https://github.com/junegunn/vim-plug >
2015-07-13 06:22:46 -04:00
2015-03-14 16:02:10 -04:00
Plug 'fatih/vim-go'
* https://github.com/Shougo/neobundle.vim >
2015-07-13 06:22:46 -04:00
2015-03-14 16:02:10 -04:00
NeoBundle 'fatih/vim-go'
<
* https://github.com/gmarik/vundle >
Plugin 'fatih/vim-go'
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
* Vim |packages| (since Vim 7.4.1528)
>
git clone https://github.com/fatih/vim-go.git \
~/.vim/pack/plugins/start/vim-go
2015-03-14 16:02:10 -04:00
<
* Manual >
2015-07-13 06:22:46 -04:00
2015-03-14 16:02:10 -04:00
Copy all of the files into your `~/.vim` directory
<
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
Please be sure all necessary binaries are installed (such as `gocode`,
`godef`, `goimports`, etc.). You can easily install them with the included
|:GoInstallBinaries| command. If you invoke it, all necessary binaries will be
automatically downloaded and installed to your `$GOBIN` environment (if not
set it will use `$GOPATH/bin`). It requires `git` for fetching the individual
Go packages.
2014-10-31 17:30:24 -04:00
* Autocompletion is enabled by default via `<C-x><C-o>`, to get real-time
completion (completion by type) install:
2016-02-20 08:13:10 -05:00
https://github.com/Shougo/neocomplete.vim for Vim or
https://github.com/Shougo/deoplete.nvim and
https://github.com/zchee/deoplete-go for Neovim
2014-10-31 17:30:24 -04:00
* To get displayed source code tag informations on a sidebar install
https://github.com/majutsushi/tagbar.
* For snippet feature install:
2016-02-20 08:13:10 -05:00
https://github.com/Shougo/neosnippet.vim or
https://github.com/SirVer/ultisnips.
2016-08-02 08:48:32 -04:00
* For a better documentation viewer check out:
https://github.com/garyburd/go-explorer
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
==============================================================================
COMMANDS *go-commands*
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*:GoPath*
2015-07-13 06:22:46 -04:00
:GoPath [path]
2015-12-08 08:20:04 -05:00
GoPath sets and overrides GOPATH with the given {path}. If no {path} is
2015-07-13 06:22:46 -04:00
given it shows the current GOPATH. If `""` is given as path, it clears
2016-08-02 08:48:32 -04:00
current `GOPATH` which was set with |:GoPath| and restores `GOPATH` back
to the initial value which was sourced when Vim was started.
2015-07-13 06:22:46 -04:00
2016-08-02 08:48:32 -04:00
*:GoImport*
2015-12-08 08:20:04 -05:00
:GoImport[!] [path]
2014-10-31 17:30:24 -04:00
Import ensures that the provided package {path} is imported in the current
2015-12-08 08:20:04 -05:00
Go buffer, using proper style and ordering. If {path} is already being
2014-10-31 17:30:24 -04:00
imported, an error will be displayed and the buffer will be untouched.
2015-12-08 08:20:04 -05:00
If [!] is given it will download the package with `go get`
2016-08-02 08:48:32 -04:00
*:GoImportAs*
2014-10-31 17:30:24 -04:00
:GoImportAs [localname] [path]
Same as Import, but uses a custom local name for the package.
2016-08-02 08:48:32 -04:00
*:GoDrop*
2014-10-31 17:30:24 -04:00
:GoDrop [path]
Remove the import line for the provided package {path}, if present in the
current Go buffer. If {path} is not being imported, an error will be
displayed and the buffer will be untouched.
2016-08-02 08:48:32 -04:00
*:GoLint*
2015-12-08 08:20:04 -05:00
:GoLint [packages]
2014-10-31 17:30:24 -04:00
2015-12-08 08:20:04 -05:00
Run golint for the current Go file, or for given packages.
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*:GoDoc*
2014-10-31 17:30:24 -04:00
:GoDoc [word]
Open the relevant GoDoc in split window for either the word[s] passed to
the command or by default, the word under the cursor.
2016-08-02 08:48:32 -04:00
*:GoDocBrowser*
2014-10-31 17:30:24 -04:00
:GoDocBrowser [word]
Open the relevant GoDoc in browser for either the word[s] passed to the
command or by default, the word under the cursor.
2016-08-02 08:48:32 -04:00
*:GoFmt*
2014-10-31 17:30:24 -04:00
:GoFmt
Filter the current Go buffer through gofmt. It tries to preserve cursor
position and avoids replacing the buffer with stderr output.
*:GoImports*
:GoImports
Filter the current Go buffer through goimports (needs to be installed).
`goimports` automatically discards/add import path based on the code. Like
2016-08-02 08:48:32 -04:00
|:GoFmt|, It tries to preserve cursor position and avoids replacing the
2014-10-31 17:30:24 -04:00
buffer with stderr output.
*:GoPlay*
:[range]GoPlay
Share snippet to play.golang.org. If no [range] is given it shares
the whole file, otherwise the selected lines are shared. Snippet URL
is copied to system clipboard if Vim is compiled with 'clipboard' or
'xterm-clipboard' otherwise it's get yanked into the `""` register.
2016-08-02 08:48:32 -04:00
*:GoVet*
2015-12-08 08:20:04 -05:00
:GoVet[!] [options]
2014-10-31 17:30:24 -04:00
Run `go vet` for the directory under your current file. Vet examines Go
source code and reports suspicious constructs, such as Printf calls whose
2016-08-02 08:48:32 -04:00
arguments do not align with the format string. Vet uses heuristics that do
not guarantee all reports are genuine problems, but it can find errors not
caught by the compilers.
2014-10-31 17:30:24 -04:00
2015-12-08 08:20:04 -05:00
You may optionally pass any valid go tool vet flags/options. In this case,
`go tool vet` is run in place of `go vet`. For a full list please see
`go tool vet -h`.
2015-07-13 06:22:46 -04:00
If [!] is not given the first error is jumped to.
2016-08-02 08:48:32 -04:00
*:GoDef*
2014-10-31 17:30:24 -04:00
:GoDef [identifier]
2016-04-12 04:31:09 -04:00
gd
CTRL-]
2014-10-31 17:30:24 -04:00
Goto declaration/definition for the given [identifier]. If no argument is
given, it will jump to the declaration under the cursor. By default the
2016-04-12 04:31:09 -04:00
CTRL-] key and the mapping `gd` are enabled to invoke :GoDef for the
2016-08-02 08:48:32 -04:00
identifier under the cursor. See |'g:go_def_mapping_enabled'| to disable
them.
2016-04-12 04:31:09 -04:00
2016-08-02 08:48:32 -04:00
vim-go also keeps a per-window location stack, roughly analogous to how
Vim's internal |tags| functionality works. This is pushed to every time a
jump is made using the GoDef functionality. In essence, this is a LIFO
list of file locations you have visited with :GoDef that is retained to
help you navigate software.
2016-04-12 04:31:09 -04:00
2016-08-02 08:48:32 -04:00
*:GoDefStack*
2016-05-14 07:57:54 -04:00
:GoDefStack [number]
2016-04-12 04:31:09 -04:00
2016-08-02 08:48:32 -04:00
This command Jumps to a given location in the jumpstack, retaining all
other entries. Jumps to non-existent entries will print an informative
message, but are otherwise a noop.
2016-04-12 04:31:09 -04:00
2016-08-02 08:48:32 -04:00
If no argument is given, it will print out an interactive list of all
items in the stack. Its output looks like this:
2016-04-12 04:31:09 -04:00
2016-08-02 08:48:32 -04:00
1 /path/first/file.go|1187 col 16|AddThing func(t *Thing)
> 2 /path/thing/thing.go|624 col 19|String() string
3 /path/thing/thing.go|744 col 6|func Sprintln(a ...interface{}) string
2016-04-12 04:31:09 -04:00
This list shows the identifiers that you jumped to and the file and cursor
2016-08-02 08:48:32 -04:00
position before that jump. The older jumps are at the top, the newer at
the bottom.
2016-04-12 04:31:09 -04:00
2016-08-02 08:48:32 -04:00
The '>' points to the active entry. This entry and any newer entries
below it will be replaced if |:GoDef| is done from this location. The
CTRL-t and |:GoDefPop| command will jump to the position above the active
entry.
2016-04-12 04:31:09 -04:00
Jumps to non-existent entries will print an informative message, but are
otherwise a noop.
2016-05-14 07:57:54 -04:00
*:GoDefStackClear*
2016-08-02 08:48:32 -04:00
:GoDefStackClear
2016-05-14 07:57:54 -04:00
Clears the current stack list and resets it.
2016-08-02 08:48:32 -04:00
*:GoDefPop*
2016-04-12 04:31:09 -04:00
:GoDefPop [count]
CTRL-t
2016-08-02 08:48:32 -04:00
Navigate to the [count] earlier entry in the jump stack, retaining the
newer entries. If no argument is given, it will jump to the next most
recent entry (`:GoDefPop 1`). If [count] is greater than the number of
prior entries, an error will be printed and no jump will be performed.
2016-04-12 04:31:09 -04:00
If you have used :GoDefPop to jump to an earlier location, and you issue
another :GoDef command, the current entry will be replaced, and all newer
entries will be removed, effectively resuming the stack at that location.
2016-08-02 08:48:32 -04:00
By default [count]CTRL-t is enabled to invoke :GoDefPop. Similarly,
hitting CTRL-t without a prior count is equivalent to `:GoDefPop 1`. See
|'g:go_def_mapping_enabled'| to disable this.
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*:GoRun*
2014-10-31 17:30:24 -04:00
:GoRun[!] [expand]
Build and run your current main package. By default all main files for the
2016-08-02 08:48:32 -04:00
current file is used. If an argument is passed, [expand] is used as file
2015-01-18 07:58:28 -05:00
selector. For example use `:GoRun %` to select the current file only.
2014-10-31 17:30:24 -04:00
2015-12-08 08:20:04 -05:00
You may optionally pass any valid go run flags/options. For a full list
please see `go help run`.
2014-10-31 17:30:24 -04:00
If [!] is not given the first error is jumped to.
2016-02-20 08:13:10 -05:00
If using neovim then `:GoRun` will run in a new terminal according to
2016-08-02 08:48:32 -04:00
|'g:go_term_mode'|.
2016-02-20 08:13:10 -05:00
2016-08-02 08:48:32 -04:00
*:GoBuild*
2015-12-08 08:20:04 -05:00
:GoBuild[!] [expand]
2014-10-31 17:30:24 -04:00
2016-02-20 08:13:10 -05:00
Build your package with `go build`. Errors are populated in the quickfix
window. It automatically builds only the files that depends on the current
file. `:GoBuild` doesn't produce a result file.
2016-08-02 08:48:32 -04:00
Use |:make| to create a result file.
2015-01-18 07:58:28 -05:00
You may optionally pass any valid go build flags/options. For a full list
2016-08-02 08:48:32 -04:00
please see `go help build`. Options are expanded with [expand].
2014-10-31 17:30:24 -04:00
2015-07-13 06:22:46 -04:00
If [!] is not given the first error is jumped to.
2016-02-20 08:13:10 -05:00
If using neovim then this command is fully async, it does not block the
UI.
2016-08-02 08:48:32 -04:00
*:GoGenerate*
2015-12-08 08:20:04 -05:00
:GoGenerate[!] [expand]
2015-07-13 06:22:46 -04:00
Creates or updates your auto-generated source files by running `go
generate`.
2016-08-02 08:48:32 -04:00
You may optionally pass any valid go generate flags/options. For a full
list please see `go help generate`. Options are expanded with [expand].
2015-07-13 06:22:46 -04:00
2014-10-31 17:30:24 -04:00
If [!] is not given the first error is jumped to.
2016-08-02 08:48:32 -04:00
*:GoInfo*
2014-10-31 17:30:24 -04:00
:GoInfo
2015-12-08 08:20:04 -05:00
Show type information about the identifier under the cursor. For example
2014-10-31 17:30:24 -04:00
putting it above a function call is going to show the full function
signature. It uses gocode to get the type informations.
2016-08-02 08:48:32 -04:00
*:GoInstall*
2015-12-08 08:20:04 -05:00
:GoInstall[!] [options]
2014-10-31 17:30:24 -04:00
2015-12-08 08:20:04 -05:00
Install your package with `go install`.
2016-08-02 08:48:32 -04:00
You may optionally pass any valid go install flags/options. For a full
list please see `go help install`.
2014-10-31 17:30:24 -04:00
2015-07-13 06:22:46 -04:00
If [!] is not given the first error is jumped to.
2016-08-02 08:48:32 -04:00
*:GoTest*
2015-07-13 06:22:46 -04:00
:GoTest[!] [expand]
2014-10-31 17:30:24 -04:00
2015-03-14 16:02:10 -04:00
Run the tests on your _test.go files via in your current directory. Errors
2016-08-02 08:48:32 -04:00
are populated in the quickfix window. If an argument is passed, [expand]
2016-02-20 08:13:10 -05:00
is used as file selector (useful for cases like `:GoTest ./...`).
2015-03-14 16:02:10 -04:00
2015-12-08 08:20:04 -05:00
You may optionally pass any valid go test flags/options. For a full list
please see `go help test`.
GoTest timesout automatically after 10 seconds. To customize the timeout
2016-08-02 08:48:32 -04:00
use |'g:go_test_timeout'|. This feature is disabled if any arguments are
2015-12-08 08:20:04 -05:00
passed to the `:GoTest` command.
2015-07-13 06:22:46 -04:00
If [!] is not given the first error is jumped to.
2016-02-20 08:13:10 -05:00
If using neovim `:GoTest` will run in a new terminal or run asynchronously
2016-08-02 08:48:32 -04:00
in the background according to |'g:go_term_enabled'|. You can set the mode
of the new terminal with |'g:go_term_mode'|.
2016-02-20 08:13:10 -05:00
2016-08-02 08:48:32 -04:00
*:GoTestFunc*
2015-07-13 06:22:46 -04:00
:GoTestFunc[!] [expand]
Runs :GoTest, but only on the single test function immediate to your
cursor using 'go test's '-run' flag.
Lookup is done starting at the cursor (including that line) moving up till
a matching `func Test` pattern is found or top of file is reached. Search
will not wrap around when at the top of the file.
If [!] is not given the first error is jumped to.
2016-08-02 08:48:32 -04:00
If using neovim `:GoTestFunc` will run in a new terminal or run
asynchronously in the background according to |'g:go_term_enabled'|. You
can set the mode of the new terminal with |'g:go_term_mode'|.
2016-02-20 08:13:10 -05:00
2015-03-14 16:02:10 -04:00
*:GoTestCompile*
2015-07-13 06:22:46 -04:00
:GoTestCompile[!] [expand]
2015-03-14 16:02:10 -04:00
Compile your _test.go files via in your current directory. Errors are
2016-08-02 08:48:32 -04:00
populated in the quickfix window. If an argument is passed, [expand] is
2016-02-20 08:13:10 -05:00
used as file selector (useful for cases like `:GoTest ./...`). Useful to
not run the tests and capture/fix errors before running the tests or to
2015-03-14 16:02:10 -04:00
create test binary.
2014-10-31 17:30:24 -04:00
2015-07-13 06:22:46 -04:00
If [!] is not given the first error is jumped to.
2016-04-12 04:31:09 -04:00
If using neovim `:GoTestCompile` will run in a new terminal or run
2016-08-02 08:48:32 -04:00
asynchronously in the background according to |'g:go_term_enabled'|. You
can set the mode of the new terminal with |'g:go_term_mode'|.
2016-02-20 08:13:10 -05:00
2016-08-02 08:48:32 -04:00
*:GoCoverage*
2015-12-08 08:20:04 -05:00
:GoCoverage[!] [options]
2014-10-31 17:30:24 -04:00
2016-04-12 04:31:09 -04:00
Create a coverage profile and annotates the current file's source code. If
2016-05-14 07:57:54 -04:00
called again it rerurns the tests.
If [!] is not given the first error is jumped to.
2016-08-02 08:48:32 -04:00
*:GoCoverageToggle*
2016-05-14 07:57:54 -04:00
:GoCoverageToggle[!] [options]
Create a coverage profile and annotates the current file's source code. If
called again clears the annotation (works as a toggle).
2016-04-12 04:31:09 -04:00
If [!] is not given the first error is jumped to.
2016-08-02 08:48:32 -04:00
*:GoCoverageClear*
2016-05-14 07:57:54 -04:00
:GoCoverageClear [options]
Clears the coverage annotation.
2016-04-12 04:31:09 -04:00
*:GoCoverageBrowser*
:GoCoverageBrowser[!] [options]
2014-10-31 17:30:24 -04:00
Create a coverage profile and open a browser to display the annotated
source code of the current package.
2015-12-08 08:20:04 -05:00
You may optionally pass any valid go test flags/options, such as
`-covermode set,count,atomic`. For a full list please see `go help test`.
2015-07-13 06:22:46 -04:00
If [!] is not given the first error is jumped to.
2016-08-02 08:48:32 -04:00
*:GoErrCheck*
2015-12-08 08:20:04 -05:00
:GoErrCheck [options]
2014-10-31 17:30:24 -04:00
Check for unchecked errors in you current package. Errors are populated in
2016-02-20 08:13:10 -05:00
the quickfix window.
2015-12-08 08:20:04 -05:00
You may optionally pass any valid errcheck flags/options. For a full list
please see `errcheck -h`.
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*:GoFiles*
2014-10-31 17:30:24 -04:00
:GoFiles
Show source files that depends for the current package
2016-08-02 08:48:32 -04:00
*:GoDeps*
2014-10-31 17:30:24 -04:00
:GoDeps
Show dependencies for the current package
*:GoInstallBinaries*
:GoInstallBinaries
Download and Install all necessary Go tool binaries such as `godef`,
2016-08-02 08:48:32 -04:00
`goimports`, `gocode`, etc. under `g:go_bin_path`. Set
|'g:go_get_update'| to disable updating dependencies.
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*:GoUpdateBinaries*
2014-10-31 17:30:24 -04:00
:GoUpdateBinaries
Download and Update previously installed Go tool binaries such as `godef`,
`goimports`, `gocode`, etc.. under `g:go_bin_path`. This can be used to
update the necessary Go binaries.
2016-08-02 08:48:32 -04:00
*:GoImplements*
2014-10-31 17:30:24 -04:00
:GoImplements
2016-08-02 08:48:32 -04:00
Show "implements" relation for a selected package. A list of interfaces
2015-01-18 07:58:28 -05:00
for the type that implements an interface under the cursor (or selected
2016-02-20 08:13:10 -05:00
package) is shown in a location list.
2016-08-02 08:48:32 -04:00
*:GoRename*
2015-12-08 08:20:04 -05:00
:GoRename[!] [to]
2014-10-31 17:30:24 -04:00
Rename the identifier under the cursor to the desired new name. If no
argument is given a prompt will ask for the desired identifier.
2015-12-08 08:20:04 -05:00
If [!] is not given the first error is jumped to.
2015-07-13 06:22:46 -04:00
2016-08-02 08:48:32 -04:00
*:GoGuruScope*
2016-05-14 07:57:54 -04:00
:GoGuruScope [pattern] [pattern2] ... [patternN]
2015-07-13 06:22:46 -04:00
2016-08-02 08:48:32 -04:00
Changes the custom |'g:go_guru_scope'| setting and overrides it with the
2016-05-14 07:57:54 -04:00
given package patterns. The custom scope is cleared (unset) if `""` is
given as the only path. If no arguments is given it prints the current
2016-08-02 08:48:32 -04:00
custom scope. Example patterns are:
2016-05-14 07:57:54 -04:00
>
golang.org/x/tools/cmd/guru # a single package
golang.org/x/tools/... # all packages beneath dir
... # the entire workspace.
<
Example usage, the following sets the scope to a `github.com/fatih/color`
and to all packages under `golang.org/x/tools/`:
>
:GoGuruScope github.com/fatih/color golang.org/x/tools/...
<
The following sets it to the entire workspace:
>
:GoGuruScope ...
<
Under the hood, the patterns are all joined to a comma-separated list and
passed to `guru`'s `-scope` flag.
2015-07-13 06:22:46 -04:00
2016-08-02 08:48:32 -04:00
*:GoCallees*
2015-01-18 07:58:28 -05:00
:GoCallees
2016-08-02 08:48:32 -04:00
Show "callees" relation for a selected package. A list of possible call
2015-02-24 05:45:22 -05:00
targets for the type under the cursor (or selected package) is shown in a
2015-12-08 08:20:04 -05:00
location list.
2015-02-24 05:45:22 -05:00
2016-08-02 08:48:32 -04:00
*:GoCallers*
2015-02-24 05:45:22 -05:00
:GoCallers
2016-08-02 08:48:32 -04:00
Show "callers" relation for a selected function. A list of possible
2015-12-08 08:20:04 -05:00
callers for the selected function under the cursor is shown in a location
2015-02-24 05:45:22 -05:00
list.
2016-08-02 08:48:32 -04:00
*:GoDescribe*
2015-02-24 05:45:22 -05:00
:GoDescribe
Shows various properties of the selected syntax: its syntactic kind, its
type (for an expression), its value (for a constant expression), its size,
alignment, method set and interfaces (for a type), its declaration (for an
identifier), etc. Almost any piece of syntax may be described, and the
2016-05-14 07:57:54 -04:00
guru will try to print all the useful information it can.
2015-02-24 05:45:22 -05:00
2016-08-02 08:48:32 -04:00
*:GoCallstack*
2015-02-24 05:45:22 -05:00
:GoCallstack
2016-08-02 08:48:32 -04:00
Shows "callstack" relation for the selected function. An arbitrary path
2016-02-20 08:13:10 -05:00
from the root of the callgraph to the selected function is shown in a
2015-12-08 08:20:04 -05:00
location list. This may be useful to understand how the function is
2015-07-13 06:22:46 -04:00
reached in a given program.
2015-02-24 05:45:22 -05:00
2016-08-02 08:48:32 -04:00
*:GoFreevars*
2015-02-24 05:45:22 -05:00
:GoFreevars
Enumerates the free variables of the selection. “Free variables” is a
technical term meaning the set of variables that are referenced but not
2015-07-13 06:22:46 -04:00
defined within the selection, or loosely speaking, its inputs.
2015-02-24 05:45:22 -05:00
This information is useful if youre considering whether to refactor the
selection into a function of its own, as the free variables would be the
necessary parameters of that function. Its also useful when you want to
understand what the inputs are to a complex block of code even if you
dont plan to change it.
2016-08-02 08:48:32 -04:00
*:GoChannelPeers*
2015-02-24 05:45:22 -05:00
:GoChannelPeers
Shows the set of possible sends/receives on the channel operand of the
2016-08-02 08:48:32 -04:00
selected send or receive operation; the selection must be a `<-` token.
2015-02-24 05:45:22 -05:00
2015-07-13 06:22:46 -04:00
For example, visually select a channel operand in the form of:
2016-08-02 08:48:32 -04:00
>
done <- true
<
And call |:GoChannelPeers| on it. It will show where it was allocated, and
2015-02-24 05:45:22 -05:00
the sending and receiving endings.
2016-08-02 08:48:32 -04:00
*:GoReferrers*
2015-02-24 05:45:22 -05:00
:GoReferrers
The referrers query shows the set of identifiers that refer to the same
object as does the selected identifier, within any package in the analysis
scope.
2015-01-18 07:58:28 -05:00
2016-08-02 08:48:32 -04:00
*:GoSameIds*
2016-07-16 14:30:35 -04:00
:GoSameIds
Highlights all identifiers that are equivalent to the identifier under the
cursor.
2016-08-02 08:48:32 -04:00
*:GoSameIdsClear*
2016-07-16 14:30:35 -04:00
:GoSameIdsClear
Clears all SameIds highlights from a |:GoSameIds| call.
2016-08-02 08:48:32 -04:00
*:GoSameIdsToggle*
:GoSameIdsToggle
Toggle between |:GoSameIds| and |:GoSameIdsClear|.
*:GoSameIdsAutoToggle*
:GoSameIdsAutoToggle
Enables or disables automatic highlighting of |:GoSameIds| while moving
the cursor. This basically toggles the option |'g:go_auto_sameids'|
on/off.
If enabled it starts highlighting whenever your cursor is. If disabled it
clears and stops automatic highlighting.
*:GoMetaLinter*
2015-12-08 08:20:04 -05:00
:GoMetaLinter [path]
Calls the underlying `gometalinter` tool and displays all warnings and
2016-08-02 08:48:32 -04:00
errors in the |quickfix| window. By default the following linters are
enabled: `vet`, `golint`, and `errcheck`. This can be changed with the
|'g:go_metalinter_enabled'| variable. To override the command completely
use the variable |'g:go_metalinter_command'|. To override the maximum
linters execution time use |'g:go_metalinter_deadline'| variable.
2015-12-08 08:20:04 -05:00
2016-08-02 08:48:32 -04:00
*:GoGuruTags*
2016-05-14 07:57:54 -04:00
:GoGuruTags [tags]
2015-12-08 08:20:04 -05:00
2016-08-02 08:48:32 -04:00
Changes the custom |'g:go_guru_tags'| setting and overrides it with the
2016-02-20 08:13:10 -05:00
given build tags. This command cooperate with GoReferrers command when
2016-08-02 08:48:32 -04:00
there exist mulitiple build tags in your project, then you can set one of
the build tags for GoReferrers to find more accurate.
2015-12-08 08:20:04 -05:00
The custom build tags is cleared (unset) if `""` is given. If no arguments
is given it prints the current custom build tags.
2016-02-20 08:13:10 -05:00
*:AsmFmt*
:AsmFmt
2016-08-02 08:48:32 -04:00
Filter the current Go asm buffer through asmfmt. It tries to preserve
cursor position and avoids replacing the buffer with stderr output.
2016-02-20 08:13:10 -05:00
2016-08-02 08:48:32 -04:00
*:GoAlternate*
2016-02-20 08:13:10 -05:00
:GoAlternate[!]
2016-08-02 08:48:32 -04:00
Alternates between the implementation and test code. For example if in
main.go, switch to main_test.go. Uses the |'g:go_alternate_mode'| setting
as the command to open the file.
2016-02-20 08:13:10 -05:00
2016-08-02 08:48:32 -04:00
If [!] is given then it switches to the new file even if it does not
exist.
2016-02-20 08:13:10 -05:00
2016-08-02 08:48:32 -04:00
If you would like to override the traditional commands for alternating,
add the following to your .vimrc:
2016-02-20 08:13:10 -05:00
>
augroup go
autocmd!
2016-08-02 08:48:32 -04:00
autocmd Filetype go
\ command! -bang A call go#alternate#Switch(<bang>0, 'edit')
\| command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
\| command! -bang AS call go#alternate#Switch(<bang>0, 'split')
2016-02-20 08:13:10 -05:00
augroup END
<
2016-08-02 08:48:32 -04:00
*:GoWhicherrs*
:GoWhicherrs
Show the list of possible constants, global variables, and concrete types
for the error type under the cursor in a location list.
*:GoDecls*
2016-03-20 14:01:44 -04:00
:GoDecls [file]
2016-08-02 08:48:32 -04:00
2016-03-20 14:01:44 -04:00
Only enabled if `ctrlp.vim` is installed. If run shows all function and
type declarations for the current file. If [file] is non empty it parses
2016-08-02 08:48:32 -04:00
the given file.
By default `type` and `func` declarations are shown. This can be changed
via |'g:go_decls_includes'|.
2016-03-20 14:01:44 -04:00
2016-08-02 08:48:32 -04:00
*:GoDeclsDir*
2016-03-20 14:01:44 -04:00
:GoDeclsDir [dir]
2016-08-02 08:48:32 -04:00
2016-03-20 14:01:44 -04:00
Only enabled if `ctrlp.vim` is installed. If run shows all function and
type declarations for the current directory. If [dir] is given it parses
the given directory.
2015-01-18 07:58:28 -05:00
2016-08-02 08:48:32 -04:00
*:GoImpl*
2016-05-14 07:57:54 -04:00
:GoImpl [receiver] [interface]
Generates method stubs for implementing an interface. If no arguments is
passed it takes the identifier under the cursor to be the receiver and
asks for the interface type to be generated. If used with arguments, the
receiver and the interface needs to be specified. Example usages:
>
:GoImpl f *Foo io.Writer
:GoImpl T io.ReadWriteCloser
<
2016-08-02 08:48:32 -04:00
*:GoAddTags*
:[range]GoAddTags [key] [key1] ...
Adds field tags for the fields of a struct. If called inside a struct it
automatically add field tags with the `json` key and the value
automatically generated based on the field name. An error message is given
if it's called outside a struct definition.
If [range] is given, only the selected fields will be changed.
The default `json` can be changed by providing one or more [key]
arguments. An example of adding `xml` and `db` would be:
>
:GoAddTags xml db
<
*:GoAutoTypeInfoToggle*
:GoAutoTypeInfoToggle
Toggles |'g:go_auto_type_info'|.
*:GoFmtAutoSaveToggle*
:GoFmtAutoSaveToggle
Toggles |'g:go_fmt_autosave'|.
2016-05-14 07:57:54 -04:00
2016-08-02 08:48:32 -04:00
*:GoAsmFmtAutoSaveToggle*
:GoAsmFmtAutoSaveToggle
Toggles |'g:go_asmfmt_autosave'|.
*:GoMetalinterAutoSaveToggle*
:GoMetalinterAutoSaveToggle
Toggles |'g:go_metalinter_autosave'|.
*:GoTemplateAutoCreateToggle*
:GoTemplateAutoCreateToggle
Toggles |'g:go_template_autocreate'|.
==============================================================================
2014-10-31 17:30:24 -04:00
MAPPINGS *go-mappings*
vim-go has several <Plug> keys which can be used to create custom mappings
2016-05-14 07:57:54 -04:00
For example, to create a mapping that `go run` for the current package, create
a mapping for the `(go-run)`: >
2014-10-31 17:30:24 -04:00
au FileType go nmap <leader>r <Plug>(go-run)
2015-02-24 05:45:22 -05:00
As always one is free to create more advanced mappings or functions based with
|go-commands|. For more information please check out the mappings command
documentation in the |go-commands| section. Available <Plug> keys are:
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*(go-run)*
2014-10-31 17:30:24 -04:00
2016-05-14 07:57:54 -04:00
Calls `go run` for the current main package
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*(go-run-tab)*
2016-02-20 08:13:10 -05:00
Calls `go run` for the current file in a new terminal tab
This option is neovim only.
*(go-run-split)*
Calls `go run` for the current file in a new terminal horizontal split
This option is neovim only.
2016-08-02 08:48:32 -04:00
*(go-run-vertical)*
2016-02-20 08:13:10 -05:00
Calls `go run` for the current file in a new terminal vertical split
This option is neovim only.
2016-08-02 08:48:32 -04:00
*(go-build)*
2014-10-31 17:30:24 -04:00
Calls `go build` for the current package
2016-08-02 08:48:32 -04:00
*(go-generate)*
2015-07-13 06:22:46 -04:00
Calls `go generate` for the current package
2016-08-02 08:48:32 -04:00
*(go-info)*
2014-10-31 17:30:24 -04:00
Shows type information for the word under the cursor
2016-08-02 08:48:32 -04:00
*(go-install)*
2014-10-31 17:30:24 -04:00
Calls `go install` for the current package
2016-08-02 08:48:32 -04:00
*(go-test)*
2014-10-31 17:30:24 -04:00
Calls `go test` for the current package
2016-08-02 08:48:32 -04:00
*(go-test-func)*
2015-07-13 06:22:46 -04:00
Calls `go test -run '...'` for the test function immediate to cursor
2016-08-02 08:48:32 -04:00
*(go-test-compile)*
2015-03-14 16:02:10 -04:00
Calls `go test -c` for the current package
2016-08-02 08:48:32 -04:00
*(go-coverage)*
2014-10-31 17:30:24 -04:00
2016-05-14 07:57:54 -04:00
Calls `go test -coverprofile-temp.out` for the current package and shows the
coverage annotation.
2016-08-02 08:48:32 -04:00
*(go-coverage-clear)*
2016-05-14 07:57:54 -04:00
Clears the coverage annotation
*(go-coverage-toggle)*
Calls `go test -coverprofile-temp.out` for the current package and shows the
coverage annotation. If run agains it acts as a toggle and clears the
annotation.
2014-10-31 17:30:24 -04:00
2016-06-11 09:56:50 -04:00
*(go-imports)*
Calls `goimports` for the current package
2016-08-02 08:48:32 -04:00
*(go-vet)*
2014-10-31 17:30:24 -04:00
Calls `go vet` for the current package
2016-08-02 08:48:32 -04:00
*(go-files)*
2014-10-31 17:30:24 -04:00
Show source files that depends for the current package
2016-08-02 08:48:32 -04:00
*(go-deps)*
2014-10-31 17:30:24 -04:00
Show dependencies for the current package
2016-08-02 08:48:32 -04:00
*(go-doc)*
2014-10-31 17:30:24 -04:00
Show the relevant GoDoc for the word under the cursor in a split window
leftabove (default mode).
2016-08-02 08:48:32 -04:00
*(go-doc-split)*
2014-10-31 17:30:24 -04:00
Show the relevant GoDoc for the word under the cursor in a split window.
2016-08-02 08:48:32 -04:00
*(go-doc-vertical)*
2014-10-31 17:30:24 -04:00
Show the relevant GoDoc for the word under the cursor in a vertical split
window.
2016-08-02 08:48:32 -04:00
*(go-doc-tab)*
2014-10-31 17:30:24 -04:00
Show the relevant GoDoc for the word under the cursor in a tab window.
2016-08-02 08:48:32 -04:00
*(go-doc-browser)*
2014-10-31 17:30:24 -04:00
Show the relevant GoDoc for the word under in browser
2016-08-02 08:48:32 -04:00
*(go-def)*
2014-10-31 17:30:24 -04:00
Goto declaration/definition. Results are shown in the current buffer.
2016-08-02 08:48:32 -04:00
*(go-def-split)*
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
Goto declaration/definition. Results are shown in a split window.
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*(go-def-vertical)*
2014-10-31 17:30:24 -04:00
Goto declaration/definition. Results are shown in a vertical split window.
2016-08-02 08:48:32 -04:00
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
*(go-def-tab)*
2014-10-31 17:30:24 -04:00
Goto declaration/definition. Results are shown in a tab window.
2016-08-02 08:48:32 -04:00
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
2016-05-14 07:57:54 -04:00
*(go-def-stack)*
Shows the godef tag stack
*(go-def-stack-clear)*
2014-10-31 17:30:24 -04:00
2016-07-16 14:30:35 -04:00
Resets and clears the tag stack
2016-05-14 07:57:54 -04:00
2016-08-02 08:48:32 -04:00
*(go-def-pop)*
2016-05-14 07:57:54 -04:00
Jump to previous entry in the tag stack
2016-08-02 08:48:32 -04:00
*(go-implements)*
2014-10-31 17:30:24 -04:00
Show the interfaces that the type under the cursor implements.
2016-08-02 08:48:32 -04:00
*(go-rename)*
2014-10-31 17:30:24 -04:00
Rename the identifier under the cursor to the desired new name
2016-08-02 08:48:32 -04:00
*(go-callees)*
2015-01-18 07:58:28 -05:00
Show the call targets for the type under the cursor
2016-08-02 08:48:32 -04:00
*(go-callers)*
2015-02-24 05:45:22 -05:00
Show possible callers of selected function
2016-08-02 08:48:32 -04:00
*(go-describe)*
2015-02-24 05:45:22 -05:00
Describe selected syntax: definition, methods, etc
2016-08-02 08:48:32 -04:00
*(go-callstack)*
2015-02-24 05:45:22 -05:00
Show path from callgraph root to selected function
2016-08-02 08:48:32 -04:00
*(go-freevars)*
2015-02-24 05:45:22 -05:00
Show free variables of selection
2016-08-02 08:48:32 -04:00
*(go-channelpeers)*
2015-02-24 05:45:22 -05:00
Show send/receive corresponding to selected channel op
2016-08-02 08:48:32 -04:00
*(go-referrers)*
2015-02-24 05:45:22 -05:00
Show all refs to entity denoted by selected identifier
2016-08-02 08:48:32 -04:00
*(go-metalinter)*
2015-12-08 08:20:04 -05:00
Calls `go-metalinter` for the current directory
2015-02-24 05:45:22 -05:00
2016-08-02 08:48:32 -04:00
*(go-alternate-edit)*
2016-02-20 08:13:10 -05:00
Alternates between the implementation and test code in the current window
2016-08-02 08:48:32 -04:00
*(go-alternate-split)*
2016-02-20 08:13:10 -05:00
Alternates between the implementation and test code in a new horizontal split
2016-08-02 08:48:32 -04:00
*(go-alternate-vertical)*
2016-02-20 08:13:10 -05:00
Alternates between the implementation and test code in a new vertical split
2016-08-02 08:48:32 -04:00
*(go-import)*
2016-06-11 09:56:50 -04:00
Calls `:GoImport` for the current package
2016-08-02 08:48:32 -04:00
==============================================================================
2015-01-18 07:58:28 -05:00
TEXT OBJECTS *go-text-objects*
vim-go comes with several custom |text-objects| that can be used to operate
upon regions of text. vim-go currently defines the following text objects:
*go-v_af* *go-af*
2016-08-02 08:48:32 -04:00
af "a function", select contents from a function definition to the
closing bracket. If |'g:go_textobj_include_function_doc'| is
2016-03-20 14:01:44 -04:00
enabled it also includes the comment doc for a function
declaration. This text-object also supports literal functions.
2015-01-18 07:58:28 -05:00
*go-v_if* *go-if*
2016-03-20 14:01:44 -04:00
if "inside a function", select contents of a function,
excluding the function definition and the closing bracket. This
text-object also supports literal functions
vim-go also defines the following text motion objects:
*go-v_]]* *go-]]*
2016-08-02 08:48:32 -04:00
]] [count] forward to next function declaration. If
|'g:go_textobj_include_function_doc'| is enabled and if your
on a comment, it skips the function which the comment
2016-03-20 14:01:44 -04:00
belongs and forwards to the next function declaration.
*go-v_[[* *go-[[*
[[ [count] backward to previous function declaration.
2014-10-31 17:30:24 -04:00
2015-02-24 05:45:22 -05:00
2016-08-02 08:48:32 -04:00
==============================================================================
2016-02-20 08:13:10 -05:00
FUNCTIONS *go-functions*
*go#jobcontrol#Statusline()*
Shows the status of a job running asynchronously. Can be used to plug into the
statusline. It works to show the status per package instead of per
2016-08-02 08:48:32 -04:00
file. Assume you have three files open, all belonging to the same package, if
the package build (`:GoBuild`) is successful, all statusline's will be empty
2016-02-20 08:13:10 -05:00
(means SUCCESS), if you it fails all file's statusline will show FAILED.
2016-08-02 08:48:32 -04:00
*go#complete#GetInfo()*
2016-02-20 08:13:10 -05:00
Returns the description of the identifer under the cursor. Can be used to plug
2016-08-02 08:48:32 -04:00
into the statusline. This function is also used for |'g:go_auto_type_info'|.
2016-02-20 08:13:10 -05:00
2016-08-02 08:48:32 -04:00
==============================================================================
2014-10-31 17:30:24 -04:00
SETTINGS *go-settings*
2016-08-02 08:48:32 -04:00
*'g:go_test_timeout'*
2015-12-08 08:20:04 -05:00
Use this option to change the test timeout of |:GoTest|. By default it is
set to 10 seconds . >
let g:go_test_timeout= '10s'
<
2016-08-02 08:48:32 -04:00
*'g:go_play_browser_command'*
2014-10-31 17:30:24 -04:00
Use this option to change the browser that is used to open the snippet url
posted to play.golang.org with |:GoPlay| or for the relevant documentation
used with |:GoDocBrowser|. By default it tries to find it automatically for
the current OS. >
2015-12-08 08:20:04 -05:00
let g:go_play_browser_command = ''
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_play_open_browser'*
2014-10-31 17:30:24 -04:00
Use this option to open browser after posting the snippet to play.golang.org
with |:GoPlay|. By default it's enabled. >
let g:go_play_open_browser = 1
<
2016-08-02 08:48:32 -04:00
*'g:go_auto_type_info'*
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
Use this option to show the type info (|:GoInfo|) for the word under the
cursor automatically. Whenever the cursor changes the type info will be
updated. By default it's disabled.
2016-07-16 14:30:35 -04:00
>
2014-10-31 17:30:24 -04:00
let g:go_auto_type_info = 0
<
2016-08-02 08:48:32 -04:00
*'g:go_auto_sameids'*
2015-07-13 06:22:46 -04:00
2016-07-16 14:30:35 -04:00
Use this option to highlight all uses of the identifier under the cursor
(:GoSameIds) automatically. By default it's disabled.
>
let g:go_auto_sameids = 0
<
2016-08-02 08:48:32 -04:00
*'g:go_jump_to_error'*
2015-07-13 06:22:46 -04:00
Use this option to enable/disable passing the bang attribute to the mappings
|(go-build)|, |(go-run)|, etc.. When enabled it will jump to the first error
automatically (means it will NOT pass the bang attribute to the appropriate
command, i.e: (go-run) -> :GoRun ). Note, that calling this doesn't have any
affect on calling the commands manually. This setting is only useful for
changing the behaviour of our custom static mappings. By default it's enabled.
>
let g:go_jump_to_error = 1
<
2016-08-02 08:48:32 -04:00
*'g:go_fmt_autosave'*
2014-10-31 17:30:24 -04:00
Use this option to auto |:GoFmt| on save. By default it's enabled >
let g:go_fmt_autosave = 1
<
2016-08-02 08:48:32 -04:00
*'g:go_fmt_command'*
2014-10-31 17:30:24 -04:00
Use this option to define which tool is used to gofmt. By default `gofmt` is
used >
let g:go_fmt_command = "gofmt"
<
2016-08-02 08:48:32 -04:00
*'g:go_fmt_options'*
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
Use this option to add additional options to the |'g:go_fmt_command'|. Default
2014-10-31 17:30:24 -04:00
is empty. >
let g:go_fmt_options = ''
<
2016-08-02 08:48:32 -04:00
*'g:go_fmt_fail_silently'*
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
Use this option to disable showing a location list when |'g:go_fmt_command'|
2016-02-20 08:13:10 -05:00
fails. By default the location list is shown. >
2014-10-31 17:30:24 -04:00
let g:go_fmt_fail_silently = 0
<
2016-08-02 08:48:32 -04:00
*'g:go_fmt_experimental'*
2015-01-18 07:58:28 -05:00
Use this option to enable fmt's experimental mode. This experimental mode is
superior to the current mode as it fully saves the undo history, so undo/redo
2015-07-13 06:22:46 -04:00
doesn't break. However it's slows (creates/deletes a file for every save) and
it's causing problems on some Vim versions. By default it's disabled. >
2015-01-18 07:58:28 -05:00
2015-07-13 06:22:46 -04:00
let g:go_fmt_experimental = 0
2015-01-18 07:58:28 -05:00
<
2016-08-02 08:48:32 -04:00
*'g:go_doc_keywordprg_enabled'*
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
Use this option to run `godoc` on words under the cursor with the default K ,
keywordprg shortcut. Usually this shortcut is set to use the program `man`. In
Go, using `godoc` is more idiomatic. Default is enabled. >
2014-10-31 17:30:24 -04:00
let g:go_doc_keywordprg_enabled = 1
2016-06-11 09:56:50 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_def_mode'*
2016-06-11 09:56:50 -04:00
Use this option to define the command to be used for |:GoDef|. By default
`guru` is being used as it covers all edge cases. But one might also use
`godef` as it's more faster. Current valid options are: `[guru, godef]` >
let g:go_def_mode = 'guru'
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_def_mapping_enabled'*
2014-10-31 17:30:24 -04:00
2016-04-12 04:31:09 -04:00
Use this option to enable/disable the default mapping of CTRL-] and (`gd`) for
2016-08-02 08:48:32 -04:00
GoDef and CTRL-t for :GoDefPop. Disabling it allows you to map something else
to these keys or mappings. Default is enabled. >
2014-10-31 17:30:24 -04:00
let g:go_def_mapping_enabled = 1
2015-07-13 06:22:46 -04:00
<
2016-05-14 07:57:54 -04:00
*'g:go_def_reuse_buffer'*
Use this option to jump to an existing buffer for the split, vsplit and tab
mappings of |:GoDef|. By default it's disabled. >
let g:go_def_reuse_buffer = 0
<
2016-08-02 08:48:32 -04:00
*'g:go_dispatch_enabled'*
2016-05-14 07:57:54 -04:00
2016-08-02 08:48:32 -04:00
Use this option to enable/disable the use of Dispatch to execute the `:GoRun`,
`:GoBuild` and `:GoGenerate` commands. More information about Dispatch is
available at https://github.com/tpope/vim-dispatch. Default is disabled. >
2015-07-13 06:22:46 -04:00
let g:go_dispatch_enabled = 0
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_doc_command'*
2014-10-31 17:30:24 -04:00
Use this option to define which tool is used to godoc. By default `godoc` is
used >
let g:go_doc_command = "godoc"
<
2016-08-02 08:48:32 -04:00
*'g:go_doc_options'*
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
Use this option to add additional options to the |'g:go_doc_command'|. Default
2014-10-31 17:30:24 -04:00
is empty. >
let g:go_doc_options = ''
< *'g:go_bin_path'*
2015-01-18 07:58:28 -05:00
Use this option to change default path for vim-go tools when using
2016-08-02 08:48:32 -04:00
|:GoInstallBinaries| and |:GoUpdateBinaries|. If not set `$GOBIN` or
2014-10-31 17:30:24 -04:00
`$GOPATH/bin` is used. >
let g:go_bin_path = ""
<
2016-08-02 08:48:32 -04:00
*'g:go_snippet_engine'*
2014-10-31 17:30:24 -04:00
Use this option to define the default snippet engine. By default "ultisnips"
is used. Use "neosnippet" for neosnippet.vim: >
let g:go_snippet_engine = "ultisnips"
<
2016-08-02 08:48:32 -04:00
*'g:go_snippet_case_type'*
2016-07-16 14:30:35 -04:00
Use this option to define the default conversion type of snippet expansion for
field tags. For the following case, if `snakecase` is used the `json` snippet
will expand to:
>
type T struct {
FooBarQuz string `json:"foo_bar_quz"
}
<
If "camelcase" is used:
>
type T struct {
FooBarQuz string `json:"fooBarQuz"
}
<
2016-08-02 08:48:32 -04:00
By default "snakecase" is used. Current values are: ["snakecase",
"camelcase"].
2016-07-16 14:30:35 -04:00
>
let g:go_snippet_case_type = "snakecase"
<
2016-08-02 08:48:32 -04:00
*'g:go_get_update'*
2016-07-16 14:30:35 -04:00
2016-08-02 08:48:32 -04:00
Use this option to disable updating dependencies with |:GoInstallBinaries|. By
2016-06-11 09:56:50 -04:00
default this is enabled.
>
let g:go_get_update = 1
<
2016-08-02 08:48:32 -04:00
*'g:go_guru_scope'*
2015-02-24 05:45:22 -05:00
2016-05-14 07:57:54 -04:00
Use this option to define the scope of the analysis to be passed for guru
2016-08-02 08:48:32 -04:00
related commands, such as |:GoImplements|, |:GoCallers|, etc. You can change
it on-the-fly with |:GoGuruScope|. The input should be a a list of package
2016-05-14 07:57:54 -04:00
pattern. An example input might be:
2016-08-02 08:48:32 -04:00
`["github.com/fatih/color","github.com/fatih/structs"]` By default it's not
set, so the relevant commands defaults are being used.
2016-05-14 07:57:54 -04:00
>
let g:go_guru_scope = []
2015-02-24 05:45:22 -05:00
<
2016-08-02 08:48:32 -04:00
*'g:go_guru_tags'*
These options that will be automatically passed to the `-tags` option of
`go guru` when it's invoked with |:GoDef|. You can use |:GoGuruTags| to set
this. By default it's not set.
>
let g:go_guru_tags = ''
<
2015-02-24 05:45:22 -05:00
2016-08-02 08:48:32 -04:00
*'g:go_highlight_array_whitespace_error'*
2014-10-31 17:30:24 -04:00
Highlights white space after "[]". >
let g:go_highlight_array_whitespace_error = 1
<
*'g:go_highlight_chan_whitespace_error'*
2016-02-20 08:13:10 -05:00
Highlights white space around the communications operator (`<-`) that doesn't
follow the standard style. >
2014-10-31 17:30:24 -04:00
let g:go_highlight_chan_whitespace_error = 1
<
*'g:go_highlight_extra_types'*
Highlights commonly used library types (io.Reader, etc.). >
let g:go_highlight_extra_types = 1
<
*'g:go_highlight_space_tab_error'*
Highlights instances of tabs following spaces. >
let g:go_highlight_space_tab_error = 1
<
*'g:go_highlight_trailing_whitespace_error'*
Highlights trailing white space. >
let g:go_highlight_trailing_whitespace_error = 1
<
*'g:go_highlight_operators'*
2016-02-20 08:13:10 -05:00
Highlights operators such as `:=` , `==`, `-=`, etc. By default it's
2014-10-31 17:30:24 -04:00
disabled. >
2016-08-02 08:48:32 -04:00
let g:go_highlight_operators = 0
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_highlight_functions'*
2014-10-31 17:30:24 -04:00
Highlights function names. By default it's disabled. >
2016-08-02 08:48:32 -04:00
let g:go_highlight_functions = 0
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_highlight_methods'*
2014-10-31 17:30:24 -04:00
Highlights method names. By default it's disabled. >
2016-08-02 08:48:32 -04:00
let g:go_highlight_methods = 0
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_highlight_types'*
2014-10-31 17:30:24 -04:00
2016-07-03 07:53:59 -04:00
Highlights struct and interface names. By default it's disabled. >
2014-10-31 17:30:24 -04:00
2016-07-03 07:53:59 -04:00
let g:go_highlight_types = 0
2016-06-11 09:56:50 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_highlight_fields'*
2016-06-11 09:56:50 -04:00
Highlights field names. By default it's disabled. >
let g:go_highlight_fields = 0
2015-02-04 05:43:54 -05:00
<
2016-08-02 08:48:32 -04:00
*'g:go_highlight_build_constraints'*
2015-02-04 05:43:54 -05:00
Highlights build constraints. By default it's disabled. >
2016-08-02 08:48:32 -04:00
let g:go_highlight_build_constraints = 0
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_highlight_string_spellcheck'*
2015-12-08 08:20:04 -05:00
2016-02-20 08:13:10 -05:00
Use this option to highlight spelling errors in strings when |spell| is
also enabled. By default it's enabled. >
2015-12-08 08:20:04 -05:00
2016-08-02 08:48:32 -04:00
let g:go_highlight_string_spellcheck = 1
2015-12-08 08:20:04 -05:00
<
2016-08-02 08:48:32 -04:00
*'g:go_highlight_format_strings'*
2015-07-13 06:22:46 -04:00
2016-04-12 04:31:09 -04:00
Use this option to highlight printf-style operators inside string literals.
By default it's enabled. >
2016-08-02 08:48:32 -04:00
let g:go_highlight_format_strings = 1
2016-04-12 04:31:09 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_autodetect_gopath'*
2015-07-13 06:22:46 -04:00
Automatically modifies GOPATH for certain directory structures, such as for
2016-02-20 08:13:10 -05:00
the tool `godep` which has his own dependencies via the `Godeps` folder. What
2015-07-13 06:22:46 -04:00
this means is that all tools are now working with the newly modified GOPATH.
2016-08-02 08:48:32 -04:00
So |:GoDef| for example jumps to the source inside the `Godeps` (vendored)
2015-12-08 08:20:04 -05:00
source. Currently `godep` and `gb` is supported, in the near future more tool
2015-07-13 06:22:46 -04:00
supports will be added. By default it's enabled. >
2016-08-02 08:48:32 -04:00
let g:go_autodetect_gopath = 1
2015-07-13 06:22:46 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_textobj_enabled'*
2015-01-18 07:58:28 -05:00
Adds custom text objects. By default it's enabled. >
2016-08-02 08:48:32 -04:00
let g:go_textobj_enabled = 1
2015-12-08 08:20:04 -05:00
<
2016-08-02 08:48:32 -04:00
*'g:go_textobj_include_function_doc'*
Consider the comment above a function to be part of the function when using
the `af` text object and `[[` motion. By default it's enabled. >
let g:go_textobj_include_function_doc = 1
<
*'g:go_metalinter_autosave'*
2015-12-08 08:20:04 -05:00
Use this option to auto |:GoMetaLinter| on save. Only linter messages for
the active buffer will be shown. By default it's disabled >
let g:go_metalinter_autosave = 0
<
2016-08-02 08:48:32 -04:00
*'g:go_metalinter_autosave_enabled'*
2015-01-18 07:58:28 -05:00
2016-08-02 08:48:32 -04:00
Specifies the enabled linters for auto |:GoMetaLinter| on save. By
2016-02-20 08:13:10 -05:00
default it's using `vet` and `golint`.
2015-12-08 08:20:04 -05:00
>
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
<
2016-08-02 08:48:32 -04:00
*'g:go_metalinter_enabled'*
2015-12-08 08:20:04 -05:00
2016-08-02 08:48:32 -04:00
Specifies the currently enabled linters for the |:GoMetaLinter| command. By
2016-02-20 08:13:10 -05:00
default it's using `vet`, `golint` and `errcheck`.
2015-12-08 08:20:04 -05:00
>
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
<
2016-08-02 08:48:32 -04:00
*'g:go_metalinter_command'*
2015-12-08 08:20:04 -05:00
2016-08-02 08:48:32 -04:00
Overrides the command to be executed when |:GoMetaLinter| is called. This is
2015-12-08 08:20:04 -05:00
an advanced settings and is for users who want to have a complete control
2016-02-20 08:13:10 -05:00
over how `gometalinter` should be executed. By default it's empty.
2015-12-08 08:20:04 -05:00
>
let g:go_metalinter_command = ""
<
*'g:go_metalinter_deadline'*
Overrides the maximum time the linters have to complete. By default it's 5
seconds.
>
let g:go_metalinter_deadline = "5s"
<
2016-08-02 08:48:32 -04:00
*'g:go_list_height'*
2016-02-20 08:13:10 -05:00
Specifies the window height for the quickfix and location list windows. The
default value (empty) automatically sets the height to the number of items
(maximum up to 10 items to prevent large heights). Setting the value
explicitly overrides this behavior. For standard Vim behavior, set it to 10.
>
let g:go_list_height = 0
<
2016-08-02 08:48:32 -04:00
*'g:go_list_type'*
2016-02-20 08:13:10 -05:00
Specifies the type of list to use. The default value (empty) will use the
appropriate kind of list for the command that was called. Supported values are
"", "quickfix", and "locationlist". >
let g:go_list_type = ""
<
2016-08-02 08:48:32 -04:00
*'g:go_asmfmt_autosave'*
2016-02-20 08:13:10 -05:00
Use this option to auto |:AsmFmt| on save. By default it's enabled. >
let g:go_asmfmt_autosave = 1
<
2016-08-02 08:48:32 -04:00
*'g:go_term_mode'*
2015-12-08 08:20:04 -05:00
2016-02-20 08:13:10 -05:00
This option is Neovim only. Use it to change the default command used to
open a new terminal for go commands such as |:GoRun|.
The default is vsplit.
2015-12-08 08:20:04 -05:00
>
2016-02-20 08:13:10 -05:00
let g:go_term_mode = "vsplit"
<
2016-08-02 08:48:32 -04:00
*'g:go_term_height'*
*'g:go_term_width'*
2016-02-20 08:13:10 -05:00
These options are Neovim only. Use them to control the height and width of
a terminal split. By default these are not set, meaning that the height and
width are set automatically by Neovim. The height only applies to a
horizontal split and width only applies to a vertical split.
For example here is how to set each to 30.
>
let g:go_term_height = 30
let g:go_term_width = 30
<
2016-08-02 08:48:32 -04:00
*'g:go_term_enabled'*
2016-02-20 08:13:10 -05:00
This option is Neovim only. Use it to change the behavior of the test
commands. If set to 1 it opens the test commands inside a new terminal
2016-08-02 08:48:32 -04:00
according to |'g:go_term_mode'|, otherwise it will run them in the background
just like `:GoBuild` and then display the status with
|go#jobcontrol#Statusline()|. By default it is disabled.
2016-02-20 08:13:10 -05:00
>
let g:go_term_enabled = 0
<
2016-08-02 08:48:32 -04:00
*'g:go_alternate_mode'*
2016-02-20 08:13:10 -05:00
Specifies the command that |:GoAlternate| uses to open the alternate file.
By default it is set to edit.
>
let g:go_alternate_mode = "edit"
<
2016-08-02 08:48:32 -04:00
*'g:go_gorename_prefill'*
2016-02-20 08:13:10 -05:00
Specifies whether |:GoRename| prefills the new identifier name with the
2016-06-11 09:56:50 -04:00
word under the cursor. By default it is enabled.
2016-02-20 08:13:10 -05:00
>
let g:go_gorename_prefill = 1
<
2016-08-02 08:48:32 -04:00
*'g:go_gocode_autobuild'*
2016-06-11 09:56:50 -04:00
Specifies whether `gocode` should automatically build out-of-date packages
2016-08-02 08:48:32 -04:00
when their source fields are modified, in order to obtain the freshest
2016-06-11 09:56:50 -04:00
autocomplete results for them. By default it is enabled.
>
let g:go_gocode_autobuild = 1
<
2016-08-02 08:48:32 -04:00
*'g:go_gocode_propose_builtins'*
2016-06-11 09:56:50 -04:00
Specifies whether `gocode` should add built-in types, functions and constants
to an autocompletion proposals. By default it is enabled.
>
let g:go_gocode_propose_builtins = 1
2016-08-20 07:23:52 -04:00
<
*'g:go_gocode_socket_type'*
Specifies whether `gocode` should use a different socket type. By default
`unix` is enabled. Possible values: `unix`, `tcp`
>
let g:go_gocode_socket_type = 'unix'
2016-07-03 07:53:59 -04:00
<
2016-08-02 08:48:32 -04:00
*'g:go_template_autocreate'*
2016-07-03 07:53:59 -04:00
When a new Go file is created, vim-go automatically fills the buffer content
with a Go code template. By default the template under
`templates/hello_world.go` is used. This can be changed with the
2016-08-02 08:48:32 -04:00
|'g:go_template_file'| setting.
2016-02-20 08:13:10 -05:00
2016-07-03 07:53:59 -04:00
If the new file is created in an already prepopulated package (with other Go
files), in this case a Go code template with only the Go package declaration
(which is automatically determined according to the current package) is added.
2015-07-13 06:22:46 -04:00
2016-07-03 07:53:59 -04:00
By default it is enabled.
>
let g:go_template_autocreate = 1
<
2016-08-02 08:48:32 -04:00
*'g:go_template_file'*
2016-07-03 07:53:59 -04:00
Specifies the file under the `templates` folder that is used if a new Go file
2016-08-02 08:48:32 -04:00
is created. Checkout |'g:go_template_autocreate'| for more info. By default
the `hello_world.go` file is used.
2016-07-03 07:53:59 -04:00
>
let g:go_template_file = "hello_world.go"
<
2016-08-02 08:48:32 -04:00
*'g:go_decls_includes'*
Only useful if `ctrlp.vim` is installed. This sets which declarations to
show for |:GoDecls|.
It is a Comma delimited list Possible options are: {func,type}.
The default is: >
let g:go_decls_includes = 'func,type'
<
==============================================================================
2014-10-31 17:30:24 -04:00
TROUBLESHOOTING *go-troubleshooting*
2016-08-02 08:48:32 -04:00
I get "not an editor command" error when I invoke :GoXXX~
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
This happens if vim-go is not installed properly. Be sure you have added this
line into your vimrc:
2014-10-31 17:30:24 -04:00
>
2016-08-02 08:48:32 -04:00
filetype plugin indent on
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
I get a "command not found" error when I invoke :GoXXX~
If you try to call |:GoDef|, |:GoInfo| and get a command not found, check that
you have the binaries installed by using |:GoInstallBinaries|.
Before opening vim, check your current $PATH:
2014-10-31 17:30:24 -04:00
>
2016-08-02 08:48:32 -04:00
echo $PATH
2014-10-31 17:30:24 -04:00
<
2016-08-02 08:48:32 -04:00
After opening vim, run `:echo $PATH`, the output must be your current `$PATH`
plus `$GOPATH/bin` (the location where |:GoInstallBinaries| installed the
binaries).
Vim becomes slow while editing Go files~
Don't enable these options:
2014-10-31 17:30:24 -04:00
>
2016-08-02 08:48:32 -04:00
let g:go_highlight_structs = 0
let g:go_highlight_interfaces = 0
let g:go_highlight_operators = 0
<
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
I get errors when using GoInstallBinaries~
2014-10-31 17:30:24 -04:00
If you see errors like this:
>
2016-08-02 08:48:32 -04:00
Error installing golang.org/x/tools/cmd/goimports
2014-10-31 17:30:24 -04:00
<
that means your local Go setup is broken or the remote website is down. For
2016-08-02 08:48:32 -04:00
example sometimes code.google.com times out. To test, just execute a simple
`go get`:
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
go get golang.org/x/tools/cmd/goimports
2014-10-31 17:30:24 -04:00
<
You'll see a more detailed error. If this works, vim-go will work too.
2016-08-02 08:48:32 -04:00
==============================================================================
2014-10-31 17:30:24 -04:00
CREDITS *go-credits*
2016-08-02 08:48:32 -04:00
* Go Authors for official Vim plugins.
2016-05-14 07:57:54 -04:00
* Gocode, Godef, Golint, Guru, Goimports, Errcheck projects and authors of
2014-10-31 17:30:24 -04:00
those projects.
* Other vim-plugins, thanks for inspiration (vim-golang, go.vim, vim-gocode,
2016-08-02 08:48:32 -04:00
vim-godef).
* vim-go contributors: https://github.com/fatih/vim-go/graphs/contributors.
2014-10-31 17:30:24 -04:00
vim:ft=help:et:ts=2:sw=2:sts=2:norl