/
vim-go.txt
1591 lines (1160 loc) · 60 KB
/
vim-go.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*vim-go.txt* Go development plugin
*vim-go*
==============================================================================
# #
# ## ## #### ## ## ###### ####### #
# ## ## ## ### ### ## ## ## ## #
# ## ## ## #### #### ## ## ## #
# ## ## ## ## ### ## ####### ## #### ## ## #
# ## ## ## ## ## ## ## ## ## #
# ## ## ## ## ## ## ## ## ## #
# ### #### ## ## ###### ####### #
# #
==============================================================================
CONTENTS *go-contents*
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|
==============================================================================
INTRO *go-intro*
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.
* 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`.
* Create a coverage profile and display annotated source code in to see
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.
* Advanced source analysis tools utilizing guru, such as `:GoImplements`,
`: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`
* On-the-fly type information about the word under the cursor. Plug it into
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`.
* 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.
* Alternate between implementation and test code with `:GoAlternate`.
==============================================================================
INSTALL *go-install*
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.
* https://github.com/tpope/vim-pathogen >
git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go
<
* https://github.com/junegunn/vim-plug >
Plug 'fatih/vim-go'
* https://github.com/Shougo/neobundle.vim >
NeoBundle 'fatih/vim-go'
<
* https://github.com/gmarik/vundle >
Plugin 'fatih/vim-go'
* Vim |packages| (since Vim 7.4.1528)
>
git clone https://github.com/fatih/vim-go.git \
~/.vim/pack/plugins/start/vim-go
<
* Manual >
Copy all of the files into your `~/.vim` directory
<
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.
* Autocompletion is enabled by default via `<C-x><C-o>`, to get real-time
completion (completion by type) install:
https://github.com/Shougo/neocomplete.vim for Vim or
https://github.com/Shougo/deoplete.nvim and
https://github.com/zchee/deoplete-go for Neovim
* To get displayed source code tag informations on a sidebar install
https://github.com/majutsushi/tagbar.
* For snippet feature install:
https://github.com/Shougo/neosnippet.vim or
https://github.com/SirVer/ultisnips.
* For a better documentation viewer check out:
https://github.com/garyburd/go-explorer
==============================================================================
COMMANDS *go-commands*
*:GoPath*
:GoPath [path]
GoPath sets and overrides GOPATH with the given {path}. If no {path} is
given it shows the current GOPATH. If `""` is given as path, it clears
current `GOPATH` which was set with |:GoPath| and restores `GOPATH` back
to the initial value which was sourced when Vim was started.
*:GoImport*
:GoImport[!] [path]
Import ensures that the provided package {path} is imported in the current
Go buffer, using proper style and ordering. If {path} is already being
imported, an error will be displayed and the buffer will be untouched.
If [!] is given it will download the package with `go get`
*:GoImportAs*
:GoImportAs [localname] [path]
Same as Import, but uses a custom local name for the package.
*:GoDrop*
: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.
*:GoLint*
:GoLint [packages]
Run golint for the current Go file, or for given packages.
*:GoDoc*
: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.
*:GoDocBrowser*
: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.
*:GoFmt*
: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
|:GoFmt|, It tries to preserve cursor position and avoids replacing the
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.
*:GoVet*
:GoVet[!] [options]
Run `go vet` for the directory under your current file. Vet examines Go
source code and reports suspicious constructs, such as Printf calls whose
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.
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`.
If [!] is not given the first error is jumped to.
*:GoDef*
:GoDef
gd
CTRL-]
Goto declaration/definition for the declaration under the cursor. By default
the CTRL-] key and the mapping `gd` are enabled to invoke :GoDef for the
identifier under the cursor. See |'g:go_def_mapping_enabled'| to disable
them. No explicit arguments are supported.
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.
*:GoDefStack*
:GoDefStack [number]
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.
If no argument is given, it will print out an interactive list of all
items in the stack. Its output looks like this:
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
This list shows the identifiers that you jumped to and the file and cursor
position before that jump. The older jumps are at the top, the newer at
the bottom.
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.
Jumps to non-existent entries will print an informative message, but are
otherwise a noop.
*:GoDefStackClear*
:GoDefStackClear
Clears the current stack list and resets it.
*:GoDefPop*
:GoDefPop [count]
CTRL-t
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.
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.
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.
*:GoRun*
:GoRun[!] [expand]
Build and run your current main package. By default all main files for the
current file is used. If an argument is passed, [expand] is used as file
selector. For example use `:GoRun %` to select the current file only.
You may optionally pass any valid go run flags/options. For a full list
please see `go help run`.
If [!] is not given the first error is jumped to.
If using neovim then `:GoRun` will run in a new terminal according to
|'g:go_term_mode'|.
*:GoBuild*
:GoBuild[!] [expand]
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.
Use |:make| to create a result file.
You may optionally pass any valid go build flags/options. For a full list
please see `go help build`. Options are expanded with [expand].
If [!] is not given the first error is jumped to.
If using neovim then this command is fully async, it does not block the
UI.
*:GoGenerate*
:GoGenerate[!] [expand]
Creates or updates your auto-generated source files by running `go
generate`.
You may optionally pass any valid go generate flags/options. For a full
list please see `go help generate`. Options are expanded with [expand].
If [!] is not given the first error is jumped to.
*:GoInfo*
:GoInfo
Show type information about the identifier under the cursor. For example
putting it above a function call is going to show the full function
signature. By default it uses `gocode` to get the type informations. To
change the underlying tool from `gocode` to another tool, see
|g:go_info_mode|.
*:GoInstall*
:GoInstall[!] [options]
Install your package with `go install`.
You may optionally pass any valid go install flags/options. For a full
list please see `go help install`.
If [!] is not given the first error is jumped to.
*:GoTest*
:GoTest[!] [expand]
Run the tests on your _test.go files via in your current directory. Errors
are populated in the quickfix window. If an argument is passed, [expand]
is used as file selector (useful for cases like `:GoTest ./...`).
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
use |'g:go_test_timeout'|. This feature is disabled if any arguments are
passed to the `:GoTest` command.
If [!] is not given the first error is jumped to.
If using neovim `:GoTest` 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'|.
*:GoTestFunc*
: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.
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'|.
*:GoTestCompile*
:GoTestCompile[!] [expand]
Compile your _test.go files via in your current directory. Errors are
populated in the quickfix window. If an argument is passed, [expand] is
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
create test binary.
If [!] is not given the first error is jumped to.
If using neovim `:GoTestCompile` 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'|.
*:GoCoverage*
:GoCoverage[!] [options]
Create a coverage profile and annotates the current file's source code. If
called again it rerurns the tests.
If [!] is not given the first error is jumped to.
*:GoCoverageToggle*
:GoCoverageToggle[!] [options]
Create a coverage profile and annotates the current file's source code. If
called again clears the annotation (works as a toggle).
If [!] is not given the first error is jumped to.
*:GoCoverageClear*
:GoCoverageClear [options]
Clears the coverage annotation.
*:GoCoverageBrowser*
:GoCoverageBrowser[!] [options]
Create a coverage profile and open a browser to display the annotated
source code of the current package.
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`.
If [!] is not given the first error is jumped to.
*:GoErrCheck*
:GoErrCheck [options]
Check for unchecked errors in you current package. Errors are populated in
the quickfix window.
You may optionally pass any valid errcheck flags/options. For a full list
please see `errcheck -h`.
*:GoFiles*
:GoFiles
Show source files that depends for the current package
*:GoDeps*
:GoDeps
Show dependencies for the current package
*:GoInstallBinaries*
:GoInstallBinaries
Download and Install all necessary Go tool binaries such as `godef`,
`goimports`, `gocode`, etc. under `g:go_bin_path`. Set
|'g:go_get_update'| to disable updating dependencies.
*:GoUpdateBinaries*
: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.
*:GoImplements*
:GoImplements
Show "implements" relation for a selected package. A list of interfaces
for the type that implements an interface under the cursor (or selected
package) is shown in a location list.
*:GoRename*
:GoRename[!] [to]
Rename the identifier under the cursor to the desired new name. If no
argument is given a prompt will ask for the desired identifier.
If [!] is not given the first error is jumped to.
*:GoGuruScope*
:GoGuruScope [pattern] [pattern2] ... [patternN]
Changes the custom |'g:go_guru_scope'| setting and overrides it with the
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
custom scope. Example patterns are:
>
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.
*:GoCallees*
:GoCallees
Show "callees" relation for a selected package. A list of possible call
targets for the type under the cursor (or selected package) is shown in a
location list.
*:GoCallers*
:GoCallers
Show "callers" relation for a selected function. A list of possible
callers for the selected function under the cursor is shown in a location
list.
*:GoDescribe*
: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
guru will try to print all the useful information it can.
*:GoCallstack*
:GoCallstack
Shows "callstack" relation for the selected function. An arbitrary path
from the root of the callgraph to the selected function is shown in a
location list. This may be useful to understand how the function is
reached in a given program.
*:GoFreevars*
:GoFreevars
Enumerates the free variables of the selection. “Free variables” is a
technical term meaning the set of variables that are referenced but not
defined within the selection, or loosely speaking, its inputs.
This information is useful if you’re considering whether to refactor the
selection into a function of its own, as the free variables would be the
necessary parameters of that function. It’s also useful when you want to
understand what the inputs are to a complex block of code even if you
don’t plan to change it.
*:GoChannelPeers*
:GoChannelPeers
Shows the set of possible sends/receives on the channel operand of the
selected send or receive operation; the selection must be a `<-` token.
For example, visually select a channel operand in the form of:
>
done <- true
<
And call |:GoChannelPeers| on it. It will show where it was allocated, and
the sending and receiving endings.
*:GoReferrers*
: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.
*:GoSameIds*
:GoSameIds
Highlights all identifiers that are equivalent to the identifier under the
cursor.
*:GoSameIdsClear*
:GoSameIdsClear
Clears all SameIds highlights from a |:GoSameIds| call.
*: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 staying at the
same position for a configurable period of time (see 'updatetime'). If
disabled it clears and stops automatic highlighting.
*:GoMetaLinter*
:GoMetaLinter [path]
Calls the underlying `gometalinter` tool and displays all warnings and
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.
*:GoBuildTags*
:GoBuildTags [tags]
Changes the build tags for various commands. If you have any file that
uses a custom build tag, such as `//+build integration` , this command can
be used to pass it to all tools that accepts tags, such as guru, gorenate,
etc..
The build tags is cleared (unset) if `""` is given. If no arguments is
given it prints the current custom build tags.
*:AsmFmt*
:AsmFmt
Filter the current Go asm buffer through asmfmt. It tries to preserve
cursor position and avoids replacing the buffer with stderr output.
*:GoAlternate*
:GoAlternate[!]
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.
If [!] is given then it switches to the new file even if it does not
exist.
If you would like to override the traditional commands for alternating,
add the following to your .vimrc:
>
augroup go
autocmd!
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')
augroup END
<
*: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*
:GoDecls [file]
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
the given file.
By default `type` and `func` declarations are shown. This can be changed
via |'g:go_decls_includes'|.
*:GoDeclsDir*
:GoDeclsDir [dir]
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.
*:GoImpl*
: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
<
*:GoAddTags*
:[range]GoAddTags [key],[option] [key1],[option] ...
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 or if the file is not correctly
formatted.
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
<
If [option] is passed it'll either add a new tag with an option or will
modify exising tags. An example of adding `omitempty` to all `json` fields
would be:
>
:GoAddTags json,omitempty
<
You can define a constant value instead of the default field based value.
For example the following command will add ``valid:"1"`` to all fields.
>
:GoAddTags valid=1
<
*:GoRemoveTags*
:[range]GoRemoveTags [key],[option] [key1],[option1] ...
Rmove field tags for the fields of a struct. If called inside a struct it
automatically remove all field tags. An error message is given if it's
called outside a struct definition or if the file is not correctly
formatted
If [range] is given, only the selected fields will be changed.
If [key] is given, it will only remove those keys. Example:
>
:GoRemoveTags json
<
If [option] is passed with a [key], it will only remove the options.
Example, this will only remove `omitempty` options from fields containing
`json`:
>
:GoRemoveTags json,omitempty
<
*:GoAutoTypeInfoToggle*
:GoAutoTypeInfoToggle
Toggles |'g:go_auto_type_info'|.
*:GoFmtAutoSaveToggle*
:GoFmtAutoSaveToggle
Toggles |'g:go_fmt_autosave'|.
*:GoAsmFmtAutoSaveToggle*
:GoAsmFmtAutoSaveToggle
Toggles |'g:go_asmfmt_autosave'|.
*:GoMetaLinterAutoSaveToggle*
:GoMetaLinterAutoSaveToggle
Toggles |'g:go_metalinter_autosave'|.
*:GoTemplateAutoCreateToggle*
:GoTemplateAutoCreateToggle
Toggles |'g:go_template_autocreate'|.
==============================================================================
MAPPINGS *go-mappings*
vim-go has several <Plug> keys which can be used to create custom mappings
For example, to create a mapping that `go run` for the current package, create
a mapping for the `(go-run)`: >
au FileType go nmap <leader>r <Plug>(go-run)
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:
*(go-run)*
Calls `go run` for the current main package
*(go-run-tab)*
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.
*(go-run-vertical)*
Calls `go run` for the current file in a new terminal vertical split
This option is neovim only.
*(go-build)*
Calls `go build` for the current package
*(go-generate)*
Calls `go generate` for the current package
*(go-info)*
Shows type information for the word under the cursor
*(go-install)*
Calls `go install` for the current package
*(go-test)*
Calls `go test` for the current package
*(go-test-func)*
Calls `go test -run '...'` for the test function immediate to cursor
*(go-test-compile)*
Calls `go test -c` for the current package
*(go-coverage)*
Calls `go test -coverprofile-temp.out` for the current package and shows the
coverage annotation.
*(go-coverage-clear)*
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.
*(go-imports)*
Calls `goimports` for the current package
*(go-lint)*
Calls `golint` for the current package
*(go-vet)*
Calls `go vet` for the current package
*(go-files)*
Show source files that depends for the current package
*(go-deps)*
Show dependencies for the current package
*(go-doc)*
Show the relevant GoDoc for the word under the cursor in a split window
leftabove (default mode).
*(go-doc-split)*
Show the relevant GoDoc for the word under the cursor in a split window.
*(go-doc-vertical)*
Show the relevant GoDoc for the word under the cursor in a vertical split
window.
*(go-doc-tab)*
Show the relevant GoDoc for the word under the cursor in a tab window.
*(go-doc-browser)*
Show the relevant GoDoc for the word under in browser
*(go-def)*
Goto declaration/definition. Results are shown in the current buffer.
*(go-def-split)*
Goto declaration/definition. Results are shown in a split window.
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
*(go-def-vertical)*
Goto declaration/definition. Results are shown in a vertical split window.
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
*(go-def-tab)*
Goto declaration/definition. Results are shown in a tab window.
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
*(go-def-stack)*
Shows the godef tag stack
*(go-def-stack-clear)*
Resets and clears the tag stack
*(go-def-pop)*
Jump to previous entry in the tag stack
*(go-implements)*
Show the interfaces that the type under the cursor implements.
*(go-rename)*
Rename the identifier under the cursor to the desired new name
*(go-callees)*
Show the call targets for the type under the cursor
*(go-callers)*
Show possible callers of selected function
*(go-describe)*
Describe selected syntax: definition, methods, etc
*(go-callstack)*
Show path from callgraph root to selected function
*(go-freevars)*
Show free variables of selection
*(go-channelpeers)*
Show send/receive corresponding to selected channel op
*(go-referrers)*
Show all refs to entity denoted by selected identifier
*(go-metalinter)*
Calls `go-metalinter` for the current directory
*(go-alternate-edit)*
Alternates between the implementation and test code in the current window
*(go-alternate-split)*
Alternates between the implementation and test code in a new horizontal split
*(go-alternate-vertical)*
Alternates between the implementation and test code in a new vertical split
*(go-import)*
Calls `:GoImport` for the current package
==============================================================================
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*
af "a function", select contents from a function definition to the
closing bracket. If |'g:go_textobj_include_function_doc'| is
enabled it also includes the comment doc for a function
declaration. This text-object also supports literal functions.
*go-v_if* *go-if*
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-]]*
]] [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
belongs and forwards to the next function declaration.
*go-v_[[* *go-[[*
[[ [count] backward to previous function declaration.
==============================================================================
FUNCTIONS *go-functions*
*go#statusline#Show()*
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
file. Assume you have three files open, all belonging to the same package, if
the package build (`:GoBuild`) is successful, all statusline's will show
`success`, if you it fails all file's statusline will show `failed`.
To avoid always showing old status information, the status information is
cleaned for each package after `60` seconds. This can be changed with the
|g:go_statusline_duration| setting.
*go#complete#GetInfo()*