-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
vim-go.txt
2746 lines (2030 loc) · 101 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. Syntax highlighting..........................|go-syntax|
9. Debugger.....................................|go-debug|
10. FAQ/Troubleshooting..........................|go-troubleshooting|
11. Development..................................|go-development|
12. Donation.....................................|go-donation|
13. Credits......................................|go-credits|
==============================================================================
INTRO *go-intro*
Go (golang) support for Vim. vim-go comes with sensible predefined settings
(e.g. automatic `gofmt` on save), has code completion, snippet support,
improved syntax highlighting, go toolchain commands, etc. It is highly
customizable, and individual features can be toggled easily. vim-go leverages
a number of tools developed by the Go community to provide a seamless Vim
experience.
* Compile your package with |:GoBuild|, install it with |:GoInstall| or
test it with |:GoTest|. Run a single test with |:GoTestFunc|).
* Quickly execute your current file(s) with |:GoRun|.
* Improved syntax highlighting and folding.
* Debug programs with integrated `delve` support with |:GoDebugStart|.
* Code completion support via `gocode` and `gopls`.
* `gofmt` or `goimports` on save keeps the cursor position and undo history.
* Go to symbol/declaration with |:GoDef|.
* Look up documentation with |:GoDoc| or |:GoDocBrowser|.
* Easily import packages via |:GoImport|, remove them via |:GoDrop|.
* Precise type-safe renaming of identifiers with |:GoRename|.
* See which code is covered by tests with |:GoCoverage|.
* Add or remove tags on struct fields with |:GoAddTags| and |:GoRemoveTags|.
* Call `golangci-lint` with |:GoMetaLinter| to invoke all possible linters
(`golint`, `vet`, `errcheck`, `deadcode`, etc.) and put the result in the
quickfix or location list.
* Lint your code with |:GoLint|, run your code through |:GoVet| to catch
static errors, or make sure errors are checked with |:GoErrCheck|.
* Advanced source analysis tools utilizing ``gopls`, such as
* |:GoImplements| and |:GoReferrers|.
* Integrated and improved snippets, supporting `ultisnips`, `neosnippet`,
and `vim-minisnip`.
* Share your current code to `go.dev/play` with |:GoPlay|.
* On-the-fly information about the word under the cursor. Plug it into your
custom Vim function.
* Text objects such as "a function" (|go-af|) or "inner function" (|go-if|).
* Most commands are run asynchronous in Neovim and Vim 8. Fully async
building and testing.
* Integrated with the Neovim terminal, launch |:GoRun| and other Go commands
in a terminal buffer.
* Switch between `file.go` and `file_test.go` code with |:GoAlternate|.
* Supports integration with the Tagbar and ctrlp.vim plugins.
* ...and more...
==============================================================================
INSTALL *go-install*
vim-go requires at least Vim 8.1.2269 or Neovim 0.4.0. On macOS, if you are
still using your system version of vim, you can use homebrew to keep your
version of Vim up-to-date with the following terminal command:
>
brew install vim
The latest stable release, https://github.com/fatih/vim-go/releases/latest, is
the recommended version to use. If you choose to use the master branch
instead, please do so with caution; it is a _development_ branch.
vim-go follows the standard runtime path structure and should work with any of
the major plugin managers.
For Pathogen or Vim |packages|, just clone the repo. For other plugin managers
you may also need to add the lines to your vimrc to execute the plugin
manager's install command.
* Vim 8 |packages| >
git clone https://github.com/fatih/vim-go.git \
~/.vim/pack/plugins/start/vim-go
<
* 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', { 'do': ':GoUpdateBinaries' }
<
* https://github.com/Shougo/neobundle.vim >
NeoBundle 'fatih/vim-go'
<
* https://github.com/gmarik/vundle >
Plugin 'fatih/vim-go'
<
* Manual (not recommended) >
Copy all of the files into your `~/.vim` directory
<
You will also need to install all the necessary binaries. vim-go makes it easy
to install all of them by providing a command, |:GoInstallBinaries|, to
`go install` all the required binaries. The binaries will be installed to
$GOBIN or $GOPATH/bin (default: $HOME/go/bin). It requires `git`.
Depending on your installation method, you may have to generate the plugin's
|:helptags| manually (e.g. `:helptags ALL`).
Code completion is enabled by default via 'omnifunc', which you can trigger
with |i_CTRL-X_CTRL-O| (`<C-x><C-o>`).
Supported Go plugins~ *vim-go-plugins*
The following plugins are supported for use with vim-go:
* Real-time completion (Vim):
https://github.com/Shougo/neocomplete.vim
* Real-time completion (Neovim and Vim 8):
https://github.com/Shougo/deoplete.nvim
Add the following line to your vimrc. This instructs deoplete to use omni
completion for Go files.
call deoplete#custom#option('omni_patterns', { 'go': '[^. *\t]\.\w*' })
* Display source code navigation in a sidebar:
https://github.com/majutsushi/tagbar
* Snippets:
https://github.com/Shougo/neosnippet.vim or
https://github.com/SirVer/ultisnips or
https://github.com/joereynolds/vim-minisnip
* Interactive |:GoDecls| and |:GoDeclsDir|:
https://github.com/ctrlpvim/ctrlp.vim or
https://github.com/junegunn/fzf.vim or
https://github.com/Shougo/unite.vim or
https://github.com/Shougo/denite.nvim
==============================================================================
COMMANDS *go-commands*
*:GoReportGitHubIssue*
:GoReportGitHubIssue
GoReportGitHubIssue opens the default browser and starts a new bug report
with useful system information.
*: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 the linter for the directory under your current file, or for the given
packages.
If [!] is not given the first error is jumped to.
*: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. By default it opens the
documentation in `https://pkg.go.dev`. To change it see |'g:go_doc_url'|.
*: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
Adjust imports using the setting of `g:go_imports_mode`. Like |:GoFmt|, It
tries to preserve cursor position and avoids replacing the buffer with
stderr output.
*:GoPlay*
:[range]GoPlay
Share snippet to `go.dev/play`. 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 vet flags/options.
If [!] is not given the first error is jumped to.
*:GoDef*
:GoDef
gd
CTRL-]
g<C-LeftMouse>
<C-LeftMouse>
Go to declaration/definition for the identifier under the cursor. By
default the CTRL-] shortcut, the mapping `gd` and <C-LeftMouse>,
g<LeftMouse> 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.
The per-window location stack is shared with |:GoDefType|.
*:GoDefType*
:GoDefType
Go to type definition for the identifier under the cursor.
The per-window location stack is shared with |:GoDef|.
*: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'|.
The working directory will be the directory containing the current buffer.
*: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 `gopls` to get the type informations.
*: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 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 times out 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'|.
*:GoTestFile*
:GoTestFile[!] [expand]
Runs :GoTest, but only on the tests in the current file using 'go test's
'-run' flag.
If [!] is not given the first error is jumped to.
*: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.
*:GoTestCompile*
:GoTestCompile[!] [expand]
Compile your _test.go files 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.
*:GoCoverage*
:GoCoverage[!] [options]
Create a coverage profile and annotates the current file's source code. If
called again it reruns 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.
*:GoCoverageOverlay*
:GoCoverageOverlay file
Overlay the coverage profile from file.
*: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. See
`errcheck -h` for a full list.
If [!] is not given the first error is jumped to.
*:GoFiles*
:GoFiles [source_files]
Show source files for the current package. The [source_files] specifies
which file types to list. See the "// Source files" section of
`go list -h` for possible values; multiple values are accepted.
Command-line completion also works for this command.
The default is to use `GoFiles` if no arguments are given.
*:GoDeps*
:GoDeps
Show dependencies for the current package.
*:GoInstallBinaries*
:GoInstallBinaries [binaries]
Download and install all necessary Go tool binaries such as `godef`,
`goimports`, `gopls`, etc. under |'g:go_bin_path'|. If [binaries] is
supplied, then only the specified binaries will be installed. The default
is to install everything.
A specific version of a binary can be specified by appending Go's version
syntax to the binary name. e.g. `:GoInstallBinaries [email protected]`.
Set |'g:go_get_update'| to disable updating dependencies.
*:GoUpdateBinaries*
:GoUpdateBinaries [binaries]
Download and update previously installed Go tool binaries such as `godef`,
`goimports`, `gopls`, etc. under |'g:go_bin_path'|. If [binaries] is
supplied, then only the specified binaries will be updated. The default is
to update everything.
A specific version of a binary can be specified by appending Go's version
syntax to the binary name. e.g. `:GoUpdateBinaries [email protected]`.
Set |'g:go_get_update'| to disable updating dependencies.
*: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.
*:GoReferrers*
:GoReferrers
The referrers query shows the set of identifiers that refer to the same
object as does the selected identifier.
*: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 |'g:go_updatetime'|).
If disabled it clears and stops automatic highlighting.
*:GoMetaLinter*
:GoMetaLinter! [path]
Calls a metalinter tool and displays all warnings and errors in the
|quickfix| window. The linters that are enabled by default vary depending
on the value of `g:go_metalinter_command` and can be changed with
`g:go_metalinter_enabled`.
If [!] is not given the first error is jumped to.
*:GoDiagnostics*
:GoDiagnostics! [packages]
Displays the diagnostics from `gopls` for the given packages in a
|quickfix| window. The diagnostics for the current package are displayed
when no package is given. The diagnostics for all packages will be
displayed when `all` is as an argument.
Disabled when |'g:go_diagnostics_enabled'| is not set.
If [!] is not given the first error is jumped to.
*: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 gopls,
gorename, etc.
The build tags is cleared (unset) if `""` is given. If no arguments are
given it prints the current 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
<
*:GoDecls*
:GoDecls [file]
Show all function and type declarations for the current file. If
[file] is non empty it parses the given file.
Requires `ctrlp.vim` or `fzf`; it will autodetect the plugin if installed,
but you can use |'g:go_decls_mode'| to force using one or the other.
By default `type` and `func` declarations are shown. This can be changed
via |'g:go_decls_includes'|. Also see |unite-decls|, |denite-decls|.
*:GoDeclsDir*
:GoDeclsDir [dir]
Show all function and type declarations for the current directory. If
[dir] is given it parses the given directory.
*unite-decls*
*denite-decls*
:Unite decls[:path]
:Denite decls[:path]
Only enabled if `unite.vim` or `denite.nvim` is installed. Show
declarations for all functions and types on the current file or directory
or for [path] if given.
Note: `denite.nvim` requires NeoVim or Vim 8 with |:python3| enabled.
>
" show declarations on the parent directory of the current file
:Unite decls
:Denite decls
" show declarations in the file.
:Unite decls:foo/bar.go
:Denite decls:foo/bar.go
" show declarations in the directory "foo".
:Unite decls:foo
:Denite decls:foo
<
*:GoImpl*
:GoImpl [receiver] [receiver type] [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 name, its type, and the interface needs to be specified. Example
usages:
>
:GoImpl f *Foo io.Writer
:GoImpl t Type 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 existing 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] ...
Remove 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'|.
*:GoModFmtAutoSaveToggle*
:GoModFmtAutoSaveToggle
Toggles |'g:go_mod_fmt_autosave'|.
*:GoAsmFmtAutoSaveToggle*
:GoAsmFmtAutoSaveToggle
Toggles |'g:go_asmfmt_autosave'|.
*:GoMetaLinterAutoSaveToggle*
:GoMetaLinterAutoSaveToggle
Toggles |'g:go_metalinter_autosave'|.
By default, `golangci-lint` messages will be shown in the |location-list|
window. The list to use can be set using |'g:go_list_type_commands'|.
*:GoTemplateAutoCreateToggle*
:GoTemplateAutoCreateToggle
Toggles |'g:go_template_autocreate'|.
<
*:GoFillStruct*
:GoFillStruct
Use `fillstruct` to fill a struct literal with default values. Existing
values (if any) are preserved. The cursor must be on the struct you wish
to fill.
For example:
>
addr := net.Address{Name: "Ford Prefect"}
<
Becomes:
>
addr := net.Address{
Name: "Ford Prefect",
Email: "",
}
<
*:GoIfErr*
:GoIfErr
Generate if err != nil { return ... } automatically which infer the type
of return values and the numbers.
For example:
>
func doSomething() (string, error) {
f, err := os.Open("file")
}
<
Becomes:
>
func doSomething() (string, error) {
f, err := os.Open("file")
if err != nil {
return "", err
}
}
<
*:GoModFmt*
:GoModFmt
Filter the current go.mod buffer through "go mod edit -fmt" command. It
tries to preserve cursor position and avoids replacing the buffer with
stderr output.
*:GoModReload*
:GoModReload [go.mod]
Force `gopls` to reload the go.mod file. When not explicitly provided, the
go.mod file ambient to the current buffer will be used.
*:GoAddWorkspace*
:GoAddWorkspace [dir] ...
Add directories to the `gopls` workspace.
*:GoLSPDebugBrowser*
:GoLSPDebugBrowser
Open a browser to see gopls debugging information.
*:GoExtract*
:[range]GoExtract
Extract the code fragment in the selected line range to a new function and
replace the fragment with call to the function.
==============================================================================
MAPPINGS *go-mappings*
vim-go has several <Plug> keys which can be used to create custom mappings
For example, to create a mapping that calls `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-file)*
Calls `go test -run '...'` for all the tests in the current file.
*(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 again it acts as a toggle and clears the
annotation.
*(go-fmt)*
Format the current buffer.
*(go-imports)*
Adjust imports for the current buffer.
*(go-lint)*
Lints 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 window.
*(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-type)*
Goto type declaration/definition. Results are shown in the current window.
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
*(go-def-type-vertical)*
Goto type 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-type-split)*
Goto type declaration/definition. Results are shown in a split window.
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
*(go-def-type-tab)*
Goto type declaration/definition. Results are shown in a tab window.
Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.