vim-go.txt 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  1. *vim-go.txt* Go development plugin
  2. *vim-go*
  3. ==============================================================================
  4. # #
  5. # ## ## #### ## ## ###### ####### #
  6. # ## ## ## ### ### ## ## ## ## #
  7. # ## ## ## #### #### ## ## ## #
  8. # ## ## ## ## ### ## ####### ## #### ## ## #
  9. # ## ## ## ## ## ## ## ## ## #
  10. # ## ## ## ## ## ## ## ## ## #
  11. # ### #### ## ## ###### ####### #
  12. # #
  13. ==============================================================================
  14. CONTENTS *go-contents*
  15. 1. Intro........................................|go-intro|
  16. 2. Install......................................|go-install|
  17. 3. Commands.....................................|go-commands|
  18. 4. Mappings.....................................|go-mappings|
  19. 5. Text Objects.................................|go-text-objects|
  20. 6. Functions....................................|go-functions|
  21. 7. Settings.....................................|go-settings|
  22. 8. Syntax highlighting..........................|go-syntax|
  23. 9. Debugger.....................................|go-debug|
  24. 10. FAQ/Troubleshooting..........................|go-troubleshooting|
  25. 11. Development..................................|go-development|
  26. 12. Donation.....................................|go-donation|
  27. 13. Credits......................................|go-credits|
  28. ==============================================================================
  29. INTRO *go-intro*
  30. Go (golang) support for Vim. vim-go comes with sensible predefined settings
  31. (e.g. automatic `gofmt` on save), has autocomplete, snippet support, improved
  32. syntax highlighting, go toolchain commands, etc. It is highly customizable,
  33. and individual features can be toggled easily. vim-go leverages a number of
  34. tools developed by the Go community to provide a seamless Vim experience.
  35. * Compile your package with |:GoBuild|, install it with |:GoInstall| or
  36. test it with |:GoTest|. Run a single tests with |:GoTestFunc|).
  37. * Quickly execute your current file(s) with |:GoRun|.
  38. * Improved syntax highlighting and folding.
  39. * Debug programs with integrated `delve` support with |:GoDebugStart|.
  40. * Completion support via `gocode`.
  41. * `gofmt` or `goimports` on save keeps the cursor position and undo history.
  42. * Go to symbol/declaration with |:GoDef|.
  43. * Look up documentation with |:GoDoc| or |:GoDocBrowser|.
  44. * Easily import packages via |:GoImport|, remove them via |:GoDrop|.
  45. * Precise type-safe renaming of identifiers with |:GoRename|.
  46. * See which code is covered by tests with |:GoCoverage|.
  47. * Add or remove tags on struct fields with |:GoAddTags| and |:GoRemoveTags|.
  48. * Call `gometalinter` with |:GoMetaLinter| to invoke all possible linters
  49. (`golint`, `vet`, `errcheck`, `deadcode`, etc.) and put the result in the
  50. quickfix or location list.
  51. * Lint your code with |:GoLint|, run your code through |:GoVet| to catch
  52. static errors, or make sure errors are checked with |:GoErrCheck|.
  53. * Advanced source analysis tools utilizing `guru`, such as |:GoImplements|,
  54. |:GoCallees|, and |:GoReferrers|.
  55. * Automatic `GOPATH` detection which works with `gb` and `godep`. Change or
  56. display `GOPATH` with |:GoPath|.
  57. * Integrated and improved snippets, supporting `ultisnips`, `neosnippet`,
  58. and `vim-minisnip`.
  59. * Share your current code to play.golang.org with |:GoPlay|.
  60. * On-the-fly information about the word under the cursor. Plug it into your
  61. custom Vim function.
  62. * Text objects such as "a function" (|go-af|) or "inner function" (|go-if|).
  63. * Most commands are run asynchronous in Neovim and Vim 8. Fully async
  64. building and testing.
  65. * Integrated with the Neovim terminal, launch |:GoRun| and other Go commands
  66. in a terminal buffer.
  67. * Switch between `file.go` and `file_test.go` code with |:GoAlternate|.
  68. * Supports integration with the Tagbar and ctrlp.vim plugins.
  69. * ...and more...
  70. ==============================================================================
  71. INSTALL *go-install*
  72. The latest stable release, https://github.com/fatih/vim-go/releases/latest, is
  73. the recommended version to use. If you choose to use the master branch
  74. instead, please do so with caution; it is a _development_ branch.
  75. vim-go follows the standard runtime path structure and should work with any of
  76. the major plugin managers.
  77. For Pathogen or Vim |packages|, just clone the repo. For other plugin managers
  78. you may also need to add the lines to your vimrc to execute the plugin
  79. manager's install command.
  80. * Vim 8 |packages|
  81. >
  82. git clone https://github.com/fatih/vim-go.git \
  83. ~/.vim/pack/plugins/start/vim-go
  84. * https://github.com/tpope/vim-pathogen >
  85. git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go
  86. <
  87. * https://github.com/junegunn/vim-plug >
  88. Plug 'fatih/vim-go'
  89. * https://github.com/Shougo/neobundle.vim >
  90. NeoBundle 'fatih/vim-go'
  91. <
  92. * https://github.com/gmarik/vundle >
  93. Plugin 'fatih/vim-go'
  94. <
  95. * Manual (not recommended) >
  96. Copy all of the files into your `~/.vim` directory
  97. <
  98. You will also need to install all the necessary binaries. vim-go makes it easy
  99. to install all of them by providing a command, |:GoInstallBinaries|, to
  100. `go get` all the required binaries. The binaries will be installed to $GOBIN
  101. or $GOPATH/bin (default: $HOME/go/bin). It requires `git`.
  102. Depending on your installation method, you may have to generate the plugin's
  103. |:helptags| manually (e.g. `:helptags ALL`).
  104. Autocompletion is enabled by default via 'omnifunc', which you can trigger
  105. with |i_CTRL-X_CTRL-O| (`<C-x><C-o>`).
  106. Supported Go plugins~ *vim-go-plugins*
  107. The following plugins are supported for use with vim-go:
  108. * Real-time completion (Vim):
  109. https://github.com/Shougo/neocomplete.vim
  110. * Real-time completion (Neovim and Vim 8):
  111. https://github.com/Shougo/deoplete.nvim and
  112. https://github.com/zchee/deoplete-go
  113. * Display source code navigation in a sidebar:
  114. https://github.com/majutsushi/tagbar
  115. * Snippets:
  116. https://github.com/Shougo/neosnippet.vim or
  117. https://github.com/SirVer/ultisnips or
  118. https://github.com/joereynolds/vim-minisnip
  119. * For a better documentation viewer check out:
  120. https://github.com/garyburd/go-explorer
  121. * Integration with `delve` (Neovim only):
  122. https://github.com/jodosha/vim-godebug
  123. * Interactive |:GoDecls| and |:GoDeclsDir|:
  124. https://github.com/ctrlpvim/ctrlp.vim or
  125. https://github.com/junegunn/fzf.vim or
  126. https://github.com/Shougo/unite.vim or
  127. https://github.com/Shougo/denite.nvim
  128. ==============================================================================
  129. COMMANDS *go-commands*
  130. *:GoPath*
  131. :GoPath [path]
  132. GoPath sets and overrides GOPATH with the given {path}. If no {path} is
  133. given it shows the current GOPATH. If `""` is given as path, it clears
  134. current `GOPATH` which was set with |:GoPath| and restores `GOPATH` back
  135. to the initial value which was sourced when Vim was started.
  136. *:GoImport*
  137. :GoImport[!] [path]
  138. Import ensures that the provided package {path} is imported in the current
  139. Go buffer, using proper style and ordering. If {path} is already being
  140. imported, an error will be displayed and the buffer will be untouched.
  141. If [!] is given it will download the package with `go get`
  142. *:GoImportAs*
  143. :GoImportAs [localname] [path]
  144. Same as Import, but uses a custom local name for the package.
  145. *:GoDrop*
  146. :GoDrop [path]
  147. Remove the import line for the provided package {path}, if present in the
  148. current Go buffer. If {path} is not being imported, an error will be
  149. displayed and the buffer will be untouched.
  150. *:GoLint*
  151. :GoLint [packages]
  152. Run golint for the directory under your current file, or for the given
  153. packages.
  154. *:GoDoc*
  155. :GoDoc [word]
  156. Open the relevant GoDoc in split window for either the word[s] passed to
  157. the command or by default, the word under the cursor.
  158. *:GoDocBrowser*
  159. :GoDocBrowser [word]
  160. Open the relevant GoDoc in browser for either the word[s] passed to the
  161. command or by default, the word under the cursor. By default it opens the
  162. documentation in 'https://godoc.org'. To change it see |'g:go_doc_url'|.
  163. *:GoFmt*
  164. :GoFmt
  165. Filter the current Go buffer through gofmt. It tries to preserve cursor
  166. position and avoids replacing the buffer with stderr output.
  167. *:GoImports*
  168. :GoImports
  169. Filter the current Go buffer through goimports (needs to be installed).
  170. `goimports` automatically discards/add import path based on the code. Like
  171. |:GoFmt|, It tries to preserve cursor position and avoids replacing the
  172. buffer with stderr output.
  173. *:GoPlay*
  174. :[range]GoPlay
  175. Share snippet to play.golang.org. If no [range] is given it shares
  176. the whole file, otherwise the selected lines are shared. Snippet URL
  177. is copied to system clipboard if Vim is compiled with 'clipboard' or
  178. 'xterm-clipboard' otherwise it's get yanked into the `""` register.
  179. *:GoVet*
  180. :GoVet[!] [options]
  181. Run `go vet` for the directory under your current file. Vet examines Go
  182. source code and reports suspicious constructs, such as Printf calls whose
  183. arguments do not align with the format string. Vet uses heuristics that do
  184. not guarantee all reports are genuine problems, but it can find errors not
  185. caught by the compilers.
  186. You may optionally pass any valid go tool vet flags/options. In this case,
  187. `go tool vet` is run in place of `go vet`. For a full list please see
  188. `go tool vet -h`.
  189. If [!] is not given the first error is jumped to.
  190. *:GoDef*
  191. :GoDef
  192. gd
  193. CTRL-]
  194. g<C-LeftMouse>
  195. <C-LeftMouse>
  196. Goto declaration/definition for the declaration under the cursor. By
  197. default the CTRL-] shortcut, the mapping `gd` and <C-LeftMouse>,
  198. g<LeftMouse> are enabled to invoke :GoDef for the identifier under the
  199. cursor. See |'g:go_def_mapping_enabled'| to disable them. No explicit
  200. arguments are supported.
  201. vim-go also keeps a per-window location stack, roughly analogous to how
  202. Vim's internal |tags| functionality works. This is pushed to every time a
  203. jump is made using the GoDef functionality. In essence, this is a LIFO
  204. list of file locations you have visited with :GoDef that is retained to
  205. help you navigate software.
  206. *:GoDefStack*
  207. :GoDefStack [number]
  208. This command Jumps to a given location in the jumpstack, retaining all
  209. other entries. Jumps to non-existent entries will print an informative
  210. message, but are otherwise a noop.
  211. If no argument is given, it will print out an interactive list of all
  212. items in the stack. Its output looks like this:
  213. 1 /path/first/file.go|1187 col 16|AddThing func(t *Thing)
  214. > 2 /path/thing/thing.go|624 col 19|String() string
  215. 3 /path/thing/thing.go|744 col 6|func Sprintln(a ...interface{}) string
  216. This list shows the identifiers that you jumped to and the file and cursor
  217. position before that jump. The older jumps are at the top, the newer at
  218. the bottom.
  219. The '>' points to the active entry. This entry and any newer entries
  220. below it will be replaced if |:GoDef| is done from this location. The
  221. CTRL-t and |:GoDefPop| command will jump to the position above the active
  222. entry.
  223. Jumps to non-existent entries will print an informative message, but are
  224. otherwise a noop.
  225. *:GoDefStackClear*
  226. :GoDefStackClear
  227. Clears the current stack list and resets it.
  228. *:GoDefPop*
  229. :GoDefPop [count]
  230. CTRL-t
  231. Navigate to the [count] earlier entry in the jump stack, retaining the
  232. newer entries. If no argument is given, it will jump to the next most
  233. recent entry (`:GoDefPop 1`). If [count] is greater than the number of
  234. prior entries, an error will be printed and no jump will be performed.
  235. If you have used :GoDefPop to jump to an earlier location, and you issue
  236. another :GoDef command, the current entry will be replaced, and all newer
  237. entries will be removed, effectively resuming the stack at that location.
  238. By default [count]CTRL-t is enabled to invoke :GoDefPop. Similarly,
  239. hitting CTRL-t without a prior count is equivalent to `:GoDefPop 1`. See
  240. |'g:go_def_mapping_enabled'| to disable this.
  241. *:GoRun*
  242. :GoRun[!] [expand]
  243. Build and run your current main package. By default all main files for the
  244. current file is used. If an argument is passed, [expand] is used as file
  245. selector. For example use `:GoRun %` to select the current file only.
  246. You may optionally pass any valid go run flags/options. For a full list
  247. please see `go help run`.
  248. If [!] is not given the first error is jumped to.
  249. If using neovim then `:GoRun` will run in a new terminal according to
  250. |'g:go_term_mode'|.
  251. *:GoBuild*
  252. :GoBuild[!] [expand]
  253. Build your package with `go build`. Errors are populated in the quickfix
  254. window. It automatically builds only the files that depends on the current
  255. file. `:GoBuild` doesn't produce a result file.
  256. Use |:make| to create a result file.
  257. You may optionally pass any valid go build flags/options. For a full list
  258. please see `go help build`. Options are expanded with [expand].
  259. If [!] is not given the first error is jumped to.
  260. If using neovim then this command is fully async, it does not block the
  261. UI.
  262. *:GoGenerate*
  263. :GoGenerate[!] [expand]
  264. Creates or updates your auto-generated source files by running `go
  265. generate`.
  266. You may optionally pass any valid go generate flags/options. For a full
  267. list please see `go help generate`. Options are expanded with [expand].
  268. If [!] is not given the first error is jumped to.
  269. *:GoInfo*
  270. :GoInfo
  271. Show type information about the identifier under the cursor. For example
  272. putting it above a function call is going to show the full function
  273. signature. By default it uses `gocode` to get the type informations. To
  274. change the underlying tool from `gocode` to another tool, see
  275. |'g:go_info_mode'|.
  276. *:GoInstall*
  277. :GoInstall[!] [options]
  278. Install your package with `go install`.
  279. You may optionally pass any valid go install flags/options. For a full
  280. list please see `go help install`.
  281. If [!] is not given the first error is jumped to.
  282. *:GoTest*
  283. :GoTest[!] [expand]
  284. Run the tests on your _test.go files via in your current directory. Errors
  285. are populated in the quickfix window. If an argument is passed, [expand]
  286. is used as file selector (useful for cases like `:GoTest ./...`).
  287. You may optionally pass any valid go test flags/options. For a full list
  288. please see `go help test`.
  289. GoTest timesout automatically after 10 seconds. To customize the timeout
  290. use |'g:go_test_timeout'|. This feature is disabled if any arguments are
  291. passed to the `:GoTest` command.
  292. If [!] is not given the first error is jumped to.
  293. If using neovim `:GoTest` will run in a new terminal or run asynchronously
  294. in the background according to |'g:go_term_enabled'|. You can set the mode
  295. of the new terminal with |'g:go_term_mode'|.
  296. *:GoTestFunc*
  297. :GoTestFunc[!] [expand]
  298. Runs :GoTest, but only on the single test function immediate to your
  299. cursor using 'go test's '-run' flag.
  300. Lookup is done starting at the cursor (including that line) moving up till
  301. a matching `func Test` pattern is found or top of file is reached. Search
  302. will not wrap around when at the top of the file.
  303. If [!] is not given the first error is jumped to.
  304. If using neovim `:GoTestFunc` will run in a new terminal or run
  305. asynchronously in the background according to |'g:go_term_enabled'|. You
  306. can set the mode of the new terminal with |'g:go_term_mode'|.
  307. *:GoTestCompile*
  308. :GoTestCompile[!] [expand]
  309. Compile your _test.go files via in your current directory. Errors are
  310. populated in the quickfix window. If an argument is passed, [expand] is
  311. used as file selector (useful for cases like `:GoTest ./...`). Useful to
  312. not run the tests and capture/fix errors before running the tests or to
  313. create test binary.
  314. If [!] is not given the first error is jumped to.
  315. If using neovim `:GoTestCompile` will run in a new terminal or run
  316. asynchronously in the background according to |'g:go_term_enabled'|. You
  317. can set the mode of the new terminal with |'g:go_term_mode'|.
  318. *:GoCoverage*
  319. :GoCoverage[!] [options]
  320. Create a coverage profile and annotates the current file's source code. If
  321. called again it rerurns the tests.
  322. If [!] is not given the first error is jumped to.
  323. *:GoCoverageToggle*
  324. :GoCoverageToggle[!] [options]
  325. Create a coverage profile and annotates the current file's source code. If
  326. called again clears the annotation (works as a toggle).
  327. If [!] is not given the first error is jumped to.
  328. *:GoCoverageClear*
  329. :GoCoverageClear [options]
  330. Clears the coverage annotation.
  331. *:GoCoverageBrowser*
  332. :GoCoverageBrowser[!] [options]
  333. Create a coverage profile and open a browser to display the annotated
  334. source code of the current package.
  335. You may optionally pass any valid go test flags/options, such as
  336. `-covermode set,count,atomic`. For a full list please see `go help test`.
  337. If [!] is not given the first error is jumped to.
  338. *:GoErrCheck*
  339. :GoErrCheck [options]
  340. Check for unchecked errors in you current package. Errors are populated in
  341. the quickfix window.
  342. You may optionally pass any valid errcheck flags/options. See
  343. `errcheck -h` for a full list.
  344. *:GoFiles*
  345. :GoFiles [source_files]
  346. Show source files for the current package. The [source_files] specifies
  347. which file types to list. See the "// Source files" section of
  348. `go list -h` for possible values; multiple values are accepted.
  349. Command-line completion also works for this command.
  350. The default is to use `GoFiles` if no arguments are given.
  351. *:GoDeps*
  352. :GoDeps
  353. Show dependencies for the current package.
  354. *:GoInstallBinaries*
  355. :GoInstallBinaries [binaries]
  356. Download and install all necessary Go tool binaries such as `godef`,
  357. `goimports`, `gocode`, etc. under |'g:go_bin_path'|. If [binaries] is
  358. supplied, then only the specified binaries will be installed. The default
  359. is to install everything.
  360. Set |'g:go_get_update'| to disable updating dependencies.
  361. *:GoUpdateBinaries*
  362. :GoUpdateBinaries [binaries]
  363. Download and update previously installed Go tool binaries such as `godef`,
  364. `goimports`, `gocode`, etc. under |'g:go_bin_path'|. If [binaries] is
  365. supplied, then only the specified binaries will be updated. The default is
  366. to update everything.
  367. Set |'g:go_get_update'| to disable updating dependencies.
  368. *:GoImplements*
  369. :GoImplements
  370. Show "implements" relation for a selected package. A list of interfaces
  371. for the type that implements an interface under the cursor (or selected
  372. package) is shown in a location list.
  373. *:GoRename*
  374. :GoRename[!] [to]
  375. Rename the identifier under the cursor to the desired new name. If no
  376. argument is given a prompt will ask for the desired identifier.
  377. If [!] is not given the first error is jumped to.
  378. *:GoGuruScope*
  379. :GoGuruScope [pattern] [pattern2] ... [patternN]
  380. Changes the custom |'g:go_guru_scope'| setting and overrides it with the
  381. given package patterns. The custom scope is cleared (unset) if `""` is
  382. given as the only path. If no arguments is given it prints the current
  383. custom scope. Example patterns are:
  384. >
  385. golang.org/x/tools/cmd/guru # a single package
  386. golang.org/x/tools/... # all packages beneath dir
  387. ... # the entire workspace.
  388. <
  389. Example usage, the following sets the scope to a `github.com/fatih/color`
  390. and to all packages under `golang.org/x/tools/`:
  391. >
  392. :GoGuruScope github.com/fatih/color golang.org/x/tools/...
  393. <
  394. The following sets it to the entire workspace:
  395. >
  396. :GoGuruScope ...
  397. <
  398. Under the hood, the patterns are all joined to a comma-separated list and
  399. passed to `guru`'s `-scope` flag.
  400. Also see |go-guru-scope|.
  401. *:GoCallees*
  402. :GoCallees
  403. Show "callees" relation for a selected package. A list of possible call
  404. targets for the type under the cursor (or selected package) is shown in a
  405. location list.
  406. *:GoCallers*
  407. :GoCallers
  408. Show "callers" relation for a selected function. A list of possible
  409. callers for the selected function under the cursor is shown in a location
  410. list.
  411. *:GoDescribe*
  412. :GoDescribe
  413. Shows various properties of the selected syntax: its syntactic kind, its
  414. type (for an expression), its value (for a constant expression), its size,
  415. alignment, method set and interfaces (for a type), its declaration (for an
  416. identifier), etc. Almost any piece of syntax may be described, and the
  417. guru will try to print all the useful information it can.
  418. *:GoCallstack*
  419. :GoCallstack
  420. Shows "callstack" relation for the selected function. An arbitrary path
  421. from the root of the callgraph to the selected function is shown in a
  422. location list. This may be useful to understand how the function is
  423. reached in a given program.
  424. *:GoFreevars*
  425. :GoFreevars
  426. Enumerates the free variables of the selection. "Free variables" is a
  427. technical term meaning the set of variables that are referenced but not
  428. defined within the selection, or loosely speaking, its inputs.
  429. This information is useful when considering whether to refactor the
  430. selection into a function of its own, as the free variables would be the
  431. necessary parameters of that function. It's also useful when you want to
  432. understand what the inputs are to a complex block of code even if you
  433. don’t plan to change it.
  434. *:GoChannelPeers*
  435. :GoChannelPeers
  436. Shows the set of possible sends/receives on the channel operand of the
  437. selected send or receive operation; the selection must be a `<-` token.
  438. For example, visually select a channel operand in the form of:
  439. >
  440. done <- true
  441. <
  442. And call |:GoChannelPeers| on it. It will show where it was allocated, and
  443. the sending and receiving endings.
  444. *:GoReferrers*
  445. :GoReferrers
  446. The referrers query shows the set of identifiers that refer to the same
  447. object as does the selected identifier, within any package in the analysis
  448. scope.
  449. *:GoSameIds*
  450. :GoSameIds
  451. Highlights all identifiers that are equivalent to the identifier under the
  452. cursor.
  453. *:GoSameIdsClear*
  454. :GoSameIdsClear
  455. Clears all SameIds highlights from a |:GoSameIds| call.
  456. *:GoSameIdsToggle*
  457. :GoSameIdsToggle
  458. Toggle between |:GoSameIds| and |:GoSameIdsClear|.
  459. *:GoSameIdsAutoToggle*
  460. :GoSameIdsAutoToggle
  461. Enables or disables automatic highlighting of |:GoSameIds| while moving
  462. the cursor. This basically toggles the option |'g:go_auto_sameids'|
  463. on/off.
  464. If enabled it starts highlighting whenever your cursor is staying at the
  465. same position for a configurable period of time (see 'updatetime'). If
  466. disabled it clears and stops automatic highlighting.
  467. *:GoMetaLinter*
  468. :GoMetaLinter [path]
  469. Calls the underlying `gometalinter` tool and displays all warnings and
  470. errors in the |quickfix| window. By default the following linters are
  471. enabled: `vet`, `golint`, and `errcheck`. This can be changed with the
  472. |'g:go_metalinter_enabled'| variable. To override the command completely
  473. use the variable |'g:go_metalinter_command'|. To override the maximum
  474. linters execution time use |'g:go_metalinter_deadline'| variable.
  475. *:GoBuildTags*
  476. :GoBuildTags [tags]
  477. Changes the build tags for various commands. If you have any file that
  478. uses a custom build tag, such as `//+build integration` , this command can
  479. be used to pass it to all tools that accepts tags, such as guru, gorename,
  480. etc..
  481. The build tags is cleared (unset) if `""` is given. If no arguments is
  482. given it prints the current custom build tags.
  483. *:AsmFmt*
  484. :AsmFmt
  485. Filter the current Go asm buffer through asmfmt. It tries to preserve
  486. cursor position and avoids replacing the buffer with stderr output.
  487. *:GoAlternate*
  488. :GoAlternate[!]
  489. Alternates between the implementation and test code. For example if in
  490. main.go, switch to main_test.go. Uses the |'g:go_alternate_mode'| setting
  491. as the command to open the file.
  492. If [!] is given then it switches to the new file even if it does not
  493. exist.
  494. If you would like to override the traditional commands for alternating,
  495. add the following to your .vimrc:
  496. >
  497. augroup go
  498. autocmd!
  499. autocmd Filetype go
  500. \ command! -bang A call go#alternate#Switch(<bang>0, 'edit')
  501. \| command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
  502. \| command! -bang AS call go#alternate#Switch(<bang>0, 'split')
  503. augroup END
  504. <
  505. *:GoWhicherrs*
  506. :GoWhicherrs
  507. Show the list of possible constants, global variables, and concrete types
  508. for the error type under the cursor in a location list.
  509. *:GoDecls*
  510. :GoDecls [file]
  511. Show all function and type declarations for the current file. If
  512. [file] is non empty it parses the given file.
  513. Requires `ctrlp.vim` or `fzf`; it will autodetect the plugin if installed,
  514. but you can use |'g:go_decls_mode'| to force using one or the other.
  515. By default `type` and `func` declarations are shown. This can be changed
  516. via |'g:go_decls_includes'|. Also see |unite-decls|, |denite-decls|.
  517. *:GoDeclsDir*
  518. :GoDeclsDir [dir]
  519. Show all function and type declarations for the current directory. If
  520. [dir] is given it parses the given directory.
  521. *unite-decls*
  522. *denite-decls*
  523. :Unite decls[:path]
  524. :Denite decls[:path]
  525. Only enabled if `unite.vim` or `denite.nvim` is installed. Show
  526. declarations for all functions and types on the current file or directory
  527. or for [path] if given.
  528. Note: `denite.nvim` requires NeoVim or Vim 8 with |:python3| enabled.
  529. >
  530. " show declarations on the parent directory of the current file
  531. :Unite decls
  532. :Denite decls
  533. " show declarations in the file.
  534. :Unite decls:foo/bar.go
  535. :Denite decls:foo/bar.go
  536. " show declarations in the directory "foo".
  537. :Unite decls:foo
  538. :Denite decls:foo
  539. <
  540. *:GoImpl*
  541. :GoImpl [receiver] [interface]
  542. Generates method stubs for implementing an interface. If no arguments is
  543. passed it takes the identifier under the cursor to be the receiver and
  544. asks for the interface type to be generated. If used with arguments, the
  545. receiver and the interface needs to be specified. Example usages:
  546. >
  547. :GoImpl f *Foo io.Writer
  548. :GoImpl t Type io.ReadWriteCloser
  549. <
  550. *:GoAddTags*
  551. :[range]GoAddTags [key],[option] [key1],[option] ...
  552. Adds field tags for the fields of a struct. If called inside a struct it
  553. automatically add field tags with the `json` key and the value
  554. automatically generated based on the field name. An error message is given
  555. if it's called outside a struct definition or if the file is not correctly
  556. formatted.
  557. If [range] is given, only the selected fields will be changed.
  558. The default `json` can be changed by providing one or more [key]
  559. arguments. An example of adding `xml` and `db` would be:
  560. >
  561. :GoAddTags xml db
  562. <
  563. If [option] is passed it'll either add a new tag with an option or will
  564. modify existing tags. An example of adding `omitempty` to all `json`
  565. fields would be:
  566. >
  567. :GoAddTags json,omitempty
  568. <
  569. You can define a constant value instead of the default field based value.
  570. For example the following command will add ``valid:"1"`` to all fields.
  571. >
  572. :GoAddTags valid=1
  573. <
  574. *:GoRemoveTags*
  575. :[range]GoRemoveTags [key],[option] [key1],[option1] ...
  576. Rmove field tags for the fields of a struct. If called inside a struct it
  577. automatically remove all field tags. An error message is given if it's
  578. called outside a struct definition or if the file is not correctly
  579. formatted
  580. If [range] is given, only the selected fields will be changed.
  581. If [key] is given, it will only remove those keys. Example:
  582. >
  583. :GoRemoveTags json
  584. <
  585. If [option] is passed with a [key], it will only remove the options.
  586. Example, this will only remove `omitempty` options from fields containing
  587. `json`:
  588. >
  589. :GoRemoveTags json,omitempty
  590. <
  591. *:GoAutoTypeInfoToggle*
  592. :GoAutoTypeInfoToggle
  593. Toggles |'g:go_auto_type_info'|.
  594. *:GoFmtAutoSaveToggle*
  595. :GoFmtAutoSaveToggle
  596. Toggles |'g:go_fmt_autosave'|.
  597. *:GoAsmFmtAutoSaveToggle*
  598. :GoAsmFmtAutoSaveToggle
  599. Toggles |'g:go_asmfmt_autosave'|.
  600. *:GoMetaLinterAutoSaveToggle*
  601. :GoMetaLinterAutoSaveToggle
  602. Toggles |'g:go_metalinter_autosave'|.
  603. By default, `gometalinter` messages will be shown in the |location-list|
  604. window. The list to use can be set using |'g:go_list_type_commands'|.
  605. *:GoTemplateAutoCreateToggle*
  606. :GoTemplateAutoCreateToggle
  607. Toggles |'g:go_template_autocreate'|.
  608. *:GoKeyify*
  609. :GoKeyify
  610. Uses `keyify` to turn unkeyed struct literals into keyed ones.
  611. For example:
  612. >
  613. Person{"John", "Smith"}
  614. <
  615. Becomes:
  616. >
  617. Person{
  618. Name: "John",
  619. Surname: "Smith",
  620. }
  621. <
  622. *:GoFillStruct*
  623. :GoFillStruct
  624. Use `fillstruct` to fill a struct literal with default values. Existing
  625. values (if any) are preserved. The cursor must be on the struct you wish
  626. to fill.
  627. For example:
  628. >
  629. addr := net.Address{Name: "Ford Prefect"}
  630. <
  631. Becomes:
  632. >
  633. addr := net.Address{
  634. Name: "Ford Prefect",
  635. Email: "",
  636. }
  637. <
  638. ==============================================================================
  639. MAPPINGS *go-mappings*
  640. vim-go has several <Plug> keys which can be used to create custom mappings
  641. For example, to create a mapping that calls `go run` for the current package,
  642. create a mapping for the `(go-run)`: >
  643. au FileType go nmap <leader>r <Plug>(go-run)
  644. As always one is free to create more advanced mappings or functions based with
  645. |go-commands|. For more information please check out the mappings command
  646. documentation in the |go-commands| section. Available <Plug> keys are:
  647. *(go-run)*
  648. Calls `go run` for the current main package
  649. *(go-run-tab)*
  650. Calls `go run` for the current file in a new terminal tab
  651. This option is neovim only.
  652. *(go-run-split)*
  653. Calls `go run` for the current file in a new terminal horizontal split
  654. This option is neovim only.
  655. *(go-run-vertical)*
  656. Calls `go run` for the current file in a new terminal vertical split
  657. This option is neovim only.
  658. *(go-build)*
  659. Calls `go build` for the current package
  660. *(go-generate)*
  661. Calls `go generate` for the current package
  662. *(go-info)*
  663. Shows type information for the word under the cursor
  664. *(go-install)*
  665. Calls `go install` for the current package
  666. *(go-test)*
  667. Calls `go test` for the current package
  668. *(go-test-func)*
  669. Calls `go test -run '...'` for the test function immediate to cursor
  670. *(go-test-compile)*
  671. Calls `go test -c` for the current package
  672. *(go-coverage)*
  673. Calls `go test -coverprofile-temp.out` for the current package and shows the
  674. coverage annotation.
  675. *(go-coverage-clear)*
  676. Clears the coverage annotation
  677. *(go-coverage-toggle)*
  678. Calls `go test -coverprofile-temp.out` for the current package and shows the
  679. coverage annotation. If run again it acts as a toggle and clears the
  680. annotation.
  681. *(go-imports)*
  682. Calls `goimports` for the current package
  683. *(go-lint)*
  684. Calls `golint` for the current package
  685. *(go-vet)*
  686. Calls `go vet` for the current package
  687. *(go-files)*
  688. Show source files that depends for the current package
  689. *(go-deps)*
  690. Show dependencies for the current package
  691. *(go-doc)*
  692. Show the relevant GoDoc for the word under the cursor in a split window
  693. leftabove (default mode).
  694. *(go-doc-split)*
  695. Show the relevant GoDoc for the word under the cursor in a split window.
  696. *(go-doc-vertical)*
  697. Show the relevant GoDoc for the word under the cursor in a vertical split
  698. window.
  699. *(go-doc-tab)*
  700. Show the relevant GoDoc for the word under the cursor in a tab window.
  701. *(go-doc-browser)*
  702. Show the relevant GoDoc for the word under in browser
  703. *(go-def)*
  704. Goto declaration/definition. Results are shown in the current buffer.
  705. *(go-def-split)*
  706. Goto declaration/definition. Results are shown in a split window.
  707. Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
  708. *(go-def-vertical)*
  709. Goto declaration/definition. Results are shown in a vertical split window.
  710. Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
  711. *(go-def-tab)*
  712. Goto declaration/definition. Results are shown in a tab window.
  713. Jumps to an existing buffer if |'g:go_def_reuse_buffer'| is enabled.
  714. *(go-def-stack)*
  715. Shows the godef tag stack
  716. *(go-def-stack-clear)*
  717. Resets and clears the tag stack
  718. *(go-def-pop)*
  719. Jump to previous entry in the tag stack
  720. *(go-implements)*
  721. Show the interfaces that the type under the cursor implements.
  722. *(go-rename)*
  723. Rename the identifier under the cursor to the desired new name
  724. *(go-callees)*
  725. Show the call targets for the type under the cursor
  726. *(go-callers)*
  727. Show possible callers of selected function
  728. *(go-describe)*
  729. Describe selected syntax: definition, methods, etc
  730. *(go-callstack)*
  731. Show path from callgraph root to selected function
  732. *(go-freevars)*
  733. Show free variables of selection
  734. *(go-channelpeers)*
  735. Show send/receive corresponding to selected channel op
  736. *(go-referrers)*
  737. Show all refs to entity denoted by selected identifier
  738. *(go-metalinter)*
  739. Calls `go-metalinter` for the current directory
  740. *(go-alternate-edit)*
  741. Alternates between the implementation and test code in the current window
  742. *(go-alternate-split)*
  743. Alternates between the implementation and test code in a new horizontal split
  744. *(go-alternate-vertical)*
  745. Alternates between the implementation and test code in a new vertical split
  746. *(go-import)*
  747. Calls `:GoImport` for the current package
  748. ==============================================================================
  749. TEXT OBJECTS *go-text-objects*
  750. vim-go comes with several custom |text-objects| that can be used to operate
  751. upon regions of text. vim-go currently defines the following text objects:
  752. *go-v_af* *go-af*
  753. af "a function", select contents from a function definition to the
  754. closing bracket. If |'g:go_textobj_include_function_doc'| is
  755. enabled it also includes the comment doc for a function
  756. declaration. This text-object also supports literal functions.
  757. If |'g:go_textobj_include_variable'| is enabled it also
  758. includes the variable of an function assignment
  759. *go-v_if* *go-if*
  760. if "inside a function", select contents of a function,
  761. excluding the function definition and the closing bracket. This
  762. text-object also supports literal functions
  763. vim-go also defines the following text motion objects:
  764. *go-v_]]* *go-]]*
  765. ]] [count] forward to next function declaration. If
  766. |'g:go_textobj_include_function_doc'| is enabled and if your
  767. on a comment, it skips the function which the comment
  768. belongs and forwards to the next function declaration.
  769. *go-v_[[* *go-[[*
  770. [[ [count] backward to previous function declaration.
  771. ==============================================================================
  772. FUNCTIONS *go-functions*
  773. *go#statusline#Show()*
  774. Shows the status of a job running asynchronously. Can be used to plug into the
  775. statusline. It works to show the status per package instead of per
  776. file. Assume you have three files open, all belonging to the same package, if
  777. the package build (`:GoBuild`) is successful, all statusline's will show
  778. `success`, if you it fails all file's statusline will show `failed`.
  779. To avoid always showing old status information, the status information is
  780. cleaned for each package after `60` seconds. This can be changed with the
  781. |'g:go_statusline_duration'| setting.
  782. *go#complete#GetInfo()*
  783. Returns the description of the identifer under the cursor. Can be used to plug
  784. into the statusline.
  785. ==============================================================================
  786. SETTINGS *go-settings*
  787. *'g:go_test_show_name'*
  788. Show the name of each failed test before the errors and logs output by the
  789. test. By default it is disabled.
  790. >
  791. let g:go_test_show_name = 0
  792. <
  793. *'g:go_test_timeout'*
  794. Use this option to change the test timeout of |:GoTest|. By default it is
  795. set to 10 seconds . >
  796. let g:go_test_timeout= '10s'
  797. <
  798. *'g:go_play_browser_command'*
  799. Browser to use for |:GoPlay| or |:GoDocBrowser|. The url must be added with
  800. `%URL%`, and it's advisable to include `&` to make sure the shell returns. For
  801. example:
  802. >
  803. let g:go_play_browser_command = 'firefox-developer %URL% &'
  804. <
  805. By default it tries to find it automatically for the current OS. >
  806. let g:go_play_browser_command = ''
  807. <
  808. *'g:go_play_open_browser'*
  809. Use this option to open browser after posting the snippet to play.golang.org
  810. with |:GoPlay|. By default it's enabled. >
  811. let g:go_play_open_browser = 1
  812. <
  813. *'g:go_auto_type_info'*
  814. Use this option to show the type info (|:GoInfo|) for the word under the
  815. cursor automatically. Whenever the cursor changes the type info will be
  816. updated. By default it's disabled. The delay can be configured with the
  817. 'g:go_updatetime' setting.
  818. >
  819. let g:go_auto_type_info = 0
  820. <
  821. *'g:go_info_mode'*
  822. Use this option to define the command to be used for |:GoInfo|. By default
  823. `gocode` is being used as it's the fastest option. But one might also use
  824. `guru` as it's covers more cases and is more accurate. Current valid options
  825. are: `[gocode, guru]` >
  826. let g:go_info_mode = 'gocode'
  827. <
  828. *'g:go_auto_sameids'*
  829. Use this option to highlight all uses of the identifier under the cursor
  830. (:GoSameIds) automatically. By default it's disabled. The delay can be
  831. configured with the 'g:go_updatetime' setting.
  832. >
  833. let g:go_auto_sameids = 0
  834. <
  835. *'g:go_updatetime'*
  836. Use this option to configure the a custom 'updatetime' for Go source files. If
  837. set to 0, no custom time will be configured. By default it's set to 800ms.
  838. >
  839. let g:go_updatetime = 800
  840. <
  841. *'g:go_jump_to_error'*
  842. Use this option to enable/disable passing the bang attribute to the mappings
  843. |(go-build)|, |(go-run)|, etc.. When enabled it will jump to the first error
  844. automatically (means it will NOT pass the bang attribute to the appropriate
  845. command, i.e: (go-run) -> :GoRun ). Note, that calling this doesn't have any
  846. affect on calling the commands manually. This setting is only useful for
  847. changing the behaviour of our custom static mappings. By default it's enabled.
  848. >
  849. let g:go_jump_to_error = 1
  850. <
  851. *'g:go_fmt_autosave'*
  852. Use this option to auto |:GoFmt| on save. By default it's enabled >
  853. let g:go_fmt_autosave = 1
  854. <
  855. *'g:go_fmt_command'*
  856. Use this option to define which tool is used to gofmt. By default `gofmt` is
  857. used >
  858. let g:go_fmt_command = "gofmt"
  859. <
  860. *'g:go_fmt_options'*
  861. Use this option to add additional options to the |'g:go_fmt_command'|. It's
  862. value type can be either a string or a dictionary. This is due backwards
  863. compatibility. The string version will be removed in the future so please use
  864. the dictionary version. Default is empty.
  865. >
  866. let g:go_fmt_options = ''
  867. or
  868. let g:go_fmt_options = {}
  869. <
  870. The dictionary version allows you to define options for multiple binaries:
  871. >
  872. let g:go_fmt_options = {
  873. \ 'gofmt': '-s',
  874. \ 'goimports': '-local mycompany.com',
  875. \ }
  876. <
  877. *'g:go_fmt_fail_silently'*
  878. Use this option to disable showing a location list when |'g:go_fmt_command'|
  879. fails. By default the location list is shown. >
  880. let g:go_fmt_fail_silently = 0
  881. <
  882. *'g:go_fmt_experimental'*
  883. Use this option to enable fmt's experimental mode. This experimental mode is
  884. superior to the current mode as it fully saves the undo history, so undo/redo
  885. doesn't break. However it's slows (creates/deletes a file for every save) and
  886. it's causing problems on some Vim versions. By default it's disabled. >
  887. let g:go_fmt_experimental = 0
  888. <
  889. *'g:go_doc_keywordprg_enabled'*
  890. Use this option to run `godoc` on words under the cursor with |K|; this will
  891. normally run the `man` program, but for Go using `godoc` is more idiomatic. It
  892. will not override the |'keywordprg'| setting, but will run |:GoDoc|. Default
  893. is enabled. >
  894. let g:go_doc_keywordprg_enabled = 1
  895. <
  896. *'g:go_doc_height'*
  897. Maximum height for the GoDoc window created with |:GoDoc|. Default is 20. >
  898. let g:go_doc_max_height = 20
  899. <
  900. *'g:go_doc_url'*
  901. godoc server URL used when |:GoDocBrowser| is used. Change if you want to use
  902. a private internal service. Default is 'https://godoc.org'.
  903. >
  904. let g:go_doc_url = 'https://godoc.org'
  905. <
  906. *'g:go_def_mode'*
  907. Use this option to define the command to be used for |:GoDef|. By default
  908. `guru` is being used as it covers all edge cases. But one might also use
  909. `godef` as it's faster. Current valid options are: `[guru, godef]` >
  910. let g:go_def_mode = 'guru'
  911. <
  912. *'g:go_def_mapping_enabled'*
  913. Use this option to enable/disable the default mapping of CTRL-],
  914. <C-LeftMouse>, g<C-LeftMouse> and (`gd`) for GoDef and CTRL-t for :GoDefPop.
  915. Disabling it allows you to map something else to these keys or mappings.
  916. Default is enabled. >
  917. let g:go_def_mapping_enabled = 1
  918. <
  919. *'g:go_def_reuse_buffer'*
  920. Use this option to jump to an existing buffer for the split, vsplit and tab
  921. mappings of |:GoDef|. By default it's disabled. >
  922. let g:go_def_reuse_buffer = 0
  923. <
  924. *'g:go_doc_command'*
  925. Command to use for |:GoDoc|; only used when invoked with a package name. The
  926. `gogetdoc` command is always used when |:GoDoc| is used on the identifier
  927. under the cursor (i.e. without argument or from |K|). >
  928. let g:go_doc_command = ["godoc"]
  929. < *'g:go_bin_path'*
  930. Use this option to change default path for vim-go tools when using
  931. |:GoInstallBinaries| and |:GoUpdateBinaries|. If not set `$GOBIN` or
  932. `$GOPATH/bin` is used. >
  933. let g:go_bin_path = ""
  934. <
  935. *'g:go_snippet_engine'*
  936. Define the snippet engine to use. The default is to auto-detect one. Valid
  937. values are:
  938. automatic Automatically detect a snippet engine.
  939. ultisnips https://github.com/SirVer/ultisnips
  940. neosnippet https://github.com/Shougo/neosnippet.vim
  941. minisnip https://github.com/joereynolds/vim-minisnip
  942. Note: the original at KeyboardFire/vim-minisnip won't work.
  943. >
  944. let g:go_snippet_engine = "automatic"
  945. <
  946. *'g:go_get_update'*
  947. Use this option to disable updating dependencies with |:GoInstallBinaries|. By
  948. default this is enabled.
  949. >
  950. let g:go_get_update = 1
  951. <
  952. *'g:go_guru_scope'*
  953. Use this option to define the scope of the analysis to be passed for guru
  954. related commands, such as |:GoImplements|, |:GoCallers|, etc. You can change
  955. it on-the-fly with |:GoGuruScope|. The input should be a a list of package
  956. pattern. An example input might be:
  957. `["github.com/fatih/color","github.com/fatih/structs"]`
  958. Also see |go-guru-scope|.
  959. By default it's not set, so the relevant commands defaults are being used.
  960. >
  961. let g:go_guru_scope = []
  962. <
  963. *'g:go_build_tags'*
  964. These options that will be automatically passed to the `-tags` option of
  965. various tools, such as `guru`, `gorename`, etc... This is a permanent
  966. setting. A more useful way is to use |:GoBuildTags| to dynamically change or
  967. remove build tags. By default it's not set.
  968. >
  969. let g:go_build_tags = ''
  970. <
  971. *'g:go_autodetect_gopath'*
  972. Automatically modify GOPATH for certain directory structures, such as for
  973. the `godep` tool which stores dependencies in the `Godeps` folder. What this
  974. means is that all tools are now working with the newly modified GOPATH. So
  975. |:GoDef| for example jumps to the source inside the `Godeps` (vendored)
  976. source. Currently `godep` and `gb` are supported. By default it's disabled.
  977. >
  978. let g:go_autodetect_gopath = 0
  979. <
  980. *'g:go_textobj_enabled'*
  981. Adds custom text objects. By default it's enabled. >
  982. let g:go_textobj_enabled = 1
  983. <
  984. *'g:go_textobj_include_function_doc'*
  985. Consider the comment above a function to be part of the function when using
  986. the `af` text object and `[[` motion. By default it's enabled. >
  987. let g:go_textobj_include_function_doc = 1
  988. <
  989. *'g:go_textobj_include_variable'*
  990. Consider the variable of an function assignment to be part of the anonymous
  991. function when using the `af` text object. By default it's enabled. >
  992. let g:go_textobj_include_variable = 1
  993. <
  994. *'g:go_metalinter_autosave'*
  995. Use this option to auto |:GoMetaLinter| on save. Only linter messages for
  996. the active buffer will be shown.
  997. By default, `gometalinter` messages will be shown in the |location-list|
  998. window. The list to use can be set using |'g:go_list_type_commands'|.
  999. By default it's disabled >
  1000. let g:go_metalinter_autosave = 0
  1001. <
  1002. *'g:go_metalinter_autosave_enabled'*
  1003. Specifies the enabled linters for auto |:GoMetaLinter| on save. By
  1004. default it's using `vet` and `golint`.
  1005. >
  1006. let g:go_metalinter_autosave_enabled = ['vet', 'golint']
  1007. <
  1008. *'g:go_metalinter_enabled'*
  1009. Specifies the linters to enable for the |:GoMetaLinter| command. By default
  1010. it's using `vet`, `golint` and `errcheck`.
  1011. >
  1012. let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
  1013. <
  1014. *'g:go_metalinter_disabled'*
  1015. Specifies the linters to disable for the |:GoMetaLinter| command. By default
  1016. it's empty
  1017. >
  1018. let g:go_metalinter_disabled = []
  1019. <
  1020. *'g:go_metalinter_command'*
  1021. Overrides the command to be executed when |:GoMetaLinter| is called. This is
  1022. an advanced settings and is for users who want to have a complete control
  1023. over how `gometalinter` should be executed. By default it's empty.
  1024. >
  1025. let g:go_metalinter_command = ""
  1026. <
  1027. *'g:go_metalinter_deadline'*
  1028. Overrides the maximum time the linters have to complete. By default it's 5
  1029. seconds.
  1030. >
  1031. let g:go_metalinter_deadline = "5s"
  1032. <
  1033. *'g:go_list_height'*
  1034. Specifies the window height for the quickfix and location list windows. The
  1035. default value (empty) automatically sets the height to the number of items
  1036. (maximum up to 10 items to prevent large heights). Setting the value
  1037. explicitly overrides this behavior. For standard Vim behavior, set it to 10.
  1038. >
  1039. let g:go_list_height = 0
  1040. <
  1041. *'g:go_list_type'*
  1042. Specifies the type of list to use for command outputs (such as errors from
  1043. builds, results from static analysis commands, etc...). The list type for
  1044. specific commands can be overridden with |'g:go_list_type_commands'|. The
  1045. default value (empty) will use the appropriate kind of list for the command
  1046. that was called. Supported values are "", "quickfix", and "locationlist".
  1047. >
  1048. let g:go_list_type = ""
  1049. <
  1050. *'g:go_list_type_commands'*
  1051. Specifies the type of list to use for command outputs (such as errors from
  1052. builds, results from static analysis commands, etc...). When an expected key
  1053. is not present in the dictionary, |'g:go_list_type'| will be used instead.
  1054. Supported keys are "GoBuild", "GoErrCheck", "GoFmt", "GoInstall", "GoLint",
  1055. "GoMetaLinter", "GoMetaLinterAutoSave", "GoModifyTags" (used for both
  1056. :GoAddTags and :GoRemoveTags), "GoRename", "GoRun", and "GoTest". Supported
  1057. values for each command are "quickfix" and "locationlist".
  1058. >
  1059. let g:go_list_type_commands = {}
  1060. <
  1061. As an example, the following settings will change all list types to
  1062. `locationlist` except for `:GoBuild` where `quickfix` is used:
  1063. >
  1064. let g:go_list_type = "locationlist"
  1065. let g:go_list_type_commands = {"GoBuild": "quickfix"}
  1066. <
  1067. *'g:go_list_autoclose'*
  1068. Specifies whether the quickfix/location list should be closed automatically
  1069. in the absence of errors. The default value is 1.
  1070. If you prefer to keep a long running error window open, you can disable
  1071. this by setting the value to 0.
  1072. >
  1073. let g:go_list_autoclose = 1
  1074. <
  1075. *'g:go_asmfmt_autosave'*
  1076. Use this option to auto |:AsmFmt| on save. By default it's disabled. >
  1077. let g:go_asmfmt_autosave = 0
  1078. <
  1079. *'g:go_term_mode'*
  1080. This option is Neovim only. Use it to change the default command used to
  1081. open a new terminal for go commands such as |:GoRun|.
  1082. The default is vsplit.
  1083. >
  1084. let g:go_term_mode = "vsplit"
  1085. <
  1086. *'g:go_term_height'*
  1087. *'g:go_term_width'*
  1088. These options are Neovim only. Use them to control the height and width of
  1089. a terminal split. By default these are not set, meaning that the height and
  1090. width are set automatically by Neovim. The height only applies to a
  1091. horizontal split and width only applies to a vertical split.
  1092. For example here is how to set each to 30.
  1093. >
  1094. let g:go_term_height = 30
  1095. let g:go_term_width = 30
  1096. <
  1097. *'g:go_term_enabled'*
  1098. This option is Neovim only. Use it to change the behavior of the test
  1099. commands. If set to 1 it opens the test commands inside a new terminal
  1100. according to |'g:go_term_mode'|, otherwise it will run them in the background
  1101. just like `:GoBuild`. By default it is disabled.
  1102. >
  1103. let g:go_term_enabled = 0
  1104. <
  1105. *'g:go_alternate_mode'*
  1106. Specifies the command that |:GoAlternate| uses to open the alternate file.
  1107. By default it is set to edit.
  1108. >
  1109. let g:go_alternate_mode = "edit"
  1110. <
  1111. *'g:go_gorename_prefill'*
  1112. Expression to prefill the new identifier when using |:GoRename| without any
  1113. arguments. Use an empty string if you don't want to prefill anything. By
  1114. default it converts the identifier to camel case but preserves the
  1115. capitalisation of the first letter to ensure that the exported state stays the
  1116. same.
  1117. >
  1118. let g:go_gorename_prefill = 'expand("<cword>") =~# "^[A-Z]"' .
  1119. \ '? go#util#pascalcase(expand("<cword>"))' .
  1120. \ ': go#util#camelcase(expand("<cword>"))'
  1121. <
  1122. *'g:go_gocode_autobuild'*
  1123. Specifies whether `gocode` should automatically build out-of-date packages
  1124. when their source fields are modified, in order to obtain the freshest
  1125. autocomplete results for them. By default it is enabled.
  1126. >
  1127. let g:go_gocode_autobuild = 1
  1128. <
  1129. *'g:go_gocode_propose_builtins'*
  1130. Specifies whether `gocode` should add built-in types, functions and constants
  1131. to an autocompletion proposals. By default it is enabled.
  1132. >
  1133. let g:go_gocode_propose_builtins = 1
  1134. <
  1135. *'g:go_gocode_unimported_packages'*
  1136. Specifies whether `gocode` should include suggestions from unimported
  1137. packages. By default it is disabled.
  1138. >
  1139. let g:go_gocode_unimported_packages = 0
  1140. <
  1141. *'g:go_gocode_socket_type'*
  1142. Specifies whether `gocode` should use a different socket type. By default
  1143. `unix` is enabled. Possible values: `unix`, `tcp`
  1144. >
  1145. let g:go_gocode_socket_type = 'unix'
  1146. <
  1147. *'g:go_template_autocreate'*
  1148. When a new Go file is created, vim-go automatically fills the buffer content
  1149. with a Go code template. By default, the templates under the `templates`
  1150. folder are used. This can be changed with the |'g:go_template_file'| and
  1151. |'g:go_template_test_file'| settings.
  1152. If the new file is created in an already prepopulated package (with other Go
  1153. files), in this case a Go code template with only the Go package declaration
  1154. (which is automatically determined according to the current package) is added.
  1155. To always use the package name instead of the template, enable the
  1156. |'g:go_template_use_pkg'| setting.
  1157. By default it is enabled.
  1158. >
  1159. let g:go_template_autocreate = 1
  1160. <
  1161. *'g:go_template_file'*
  1162. Specifies the file under the `templates` folder that is used if a new Go file
  1163. is created. Checkout |'g:go_template_autocreate'| for more info. By default
  1164. the `hello_world.go` file is used.
  1165. >
  1166. let g:go_template_file = "hello_world.go"
  1167. <
  1168. *'g:go_template_test_file'*
  1169. Specifies the file under the `templates` folder that is used if a new Go test
  1170. file is created. Checkout |'g:go_template_autocreate'| for more info. By
  1171. default the `hello_world_test.go` file is used.
  1172. >
  1173. let g:go_template_test_file = "hello_world_test.go"
  1174. <
  1175. *'g:go_template_use_pkg'*
  1176. Specifies that, rather than using a template, the package name is used if a
  1177. new Go file is created. Checkout |'g:go_template_autocreate'| for more info.
  1178. By default the template file specified by |'g:go_template_file'| is used.
  1179. >
  1180. let g:go_template_use_pkg = 0
  1181. <
  1182. *'g:go_decls_includes'*
  1183. Only useful if `ctrlp.vim`, `unite.vim`, `denite.nvim` or `fzf` are installed.
  1184. This sets which declarations to show for |:GoDecls| (`ctrp.vim`),
  1185. |unite-decls| (`unite.vim`) and |denite-decls| (`denite.nvim`). It is a Comma
  1186. delimited list. Possible options are: {func,type}. The default is: >
  1187. let g:go_decls_includes = 'func,type'
  1188. <
  1189. *'g:go_decls_mode'*
  1190. Define the tool to be used for |:GoDecls|. Valid options are `ctrlp.vim`,
  1191. `fzf`, or an empty string; in which case it will try to autodetect either
  1192. `ctrlp.vim` or `fzf`.
  1193. >
  1194. let g:go_decls_mode = ''
  1195. <
  1196. *'g:go_echo_command_info'*
  1197. Echoes information about various Go commands, such as `:GoBuild`, `:GoTest`,
  1198. `:GoCoverage`, etc... Useful to disable if you use the statusline integration,
  1199. i.e: |go#statusline#Show()|. By default it's enabled
  1200. >
  1201. let g:go_echo_command_info = 1
  1202. <
  1203. *'g:go_echo_go_info'*
  1204. Use this option to show the identifier information when completion is done. By
  1205. default it's enabled >
  1206. let g:go_echo_go_info = 1
  1207. <
  1208. Please note that 'noshowmode' must be set for this feature to work correctly.
  1209. *'g:go_statusline_duration'*
  1210. Specifies the duration of statusline information being showed per package. By
  1211. default it's 60 seconds. Must be in milliseconds.
  1212. >
  1213. let g:go_statusline_duration = 60000
  1214. <
  1215. *'g:go_addtags_transform'*
  1216. Sets the `transform` option for `gomodifytags` when using |:GoAddTags| or if
  1217. it's being used for snippet expansion of single fields. Possible options are:
  1218. `snakecase`, `camelcase`. For the following case, if `snakecase` is used the
  1219. field will be transformed to:
  1220. >
  1221. type T struct {
  1222. FooBarQuz string `json:"foo_bar_quz"
  1223. }
  1224. <
  1225. If "camelcase" is used:
  1226. >
  1227. type T struct {
  1228. FooBarQuz string `json:"fooBarQuz"
  1229. }
  1230. <
  1231. By default "snakecase" is used. Current values are: ["snakecase",
  1232. "camelcase"].
  1233. >
  1234. let g:go_addtags_transform = 'snakecase'
  1235. <
  1236. *'g:go_debug'*
  1237. A list of options to debug; useful for development and/or reporting bugs.
  1238. Currently accepted values:
  1239. debugger-state Expose debugger state in 'g:go_debug_diag'.
  1240. debugger-commands Echo communication between vim-go and `dlv`; requests and
  1241. responses are recorded in `g:go_debug_commands`.
  1242. >
  1243. let g:go_debug = []
  1244. <
  1245. ==============================================================================
  1246. SYNTAX HIGHLIGHTING *ft-go-syntax* *go-syntax*
  1247. vim-go comes with an enhanced version of Vim's Go syntax highlighting. It
  1248. comes with a number of features, most of which are disabled by default.
  1249. The recommended settings are the default values. If you're experiencing
  1250. slowdowns in Go files and you enabled some of these options then try disabling
  1251. them; some can be resource intensive.
  1252. *'g:go_fold_enable'*
  1253. Control syntax-based folding which takes effect when 'foldmethod' is set to
  1254. `syntax`.
  1255. You can enable specific fold regions by setting an array. Possible values are:
  1256. block `{` .. `}` blocks.
  1257. import `import` block.
  1258. varconst `var` and `const` blocks.
  1259. package_comment The package comment.
  1260. comment Any comment that is not the package comment.
  1261. By default all except "comment" are enabled:
  1262. >
  1263. let g:go_fold_enable = ['block', 'import', 'varconst', 'package_comment']
  1264. <
  1265. Enable folding of only imports:
  1266. >
  1267. let g:go_fold_enable = ['import']
  1268. <
  1269. Disable everything (same as not setting 'foldmethod' to `syntax`):
  1270. >
  1271. let g:go_fold_enable = []
  1272. <
  1273. *'g:go_highlight_array_whitespace_error'*
  1274. Highlight white space after `[]`. >
  1275. let g:go_highlight_array_whitespace_error = 0
  1276. <
  1277. *'g:go_highlight_chan_whitespace_error'*
  1278. Highlight white space around the receive operator (`<-`) that doesn't follow
  1279. the standard style. >
  1280. let g:go_highlight_chan_whitespace_error = 0
  1281. <
  1282. *'g:go_highlight_extra_types'*
  1283. Highlight commonly used library types (`io.Reader`, etc.). >
  1284. let g:go_highlight_extra_types = 0
  1285. <
  1286. *'g:go_highlight_space_tab_error'*
  1287. Highlight instances of tabs following spaces. >
  1288. let g:go_highlight_space_tab_error = 0
  1289. <
  1290. *'g:go_highlight_trailing_whitespace_error'*
  1291. Highlight trailing white space. >
  1292. let g:go_highlight_trailing_whitespace_error = 0
  1293. <
  1294. *'g:go_highlight_operators'*
  1295. Highlight operators such as `:=` , `==`, `-=`, etc.
  1296. >
  1297. let g:go_highlight_operators = 0
  1298. <
  1299. *'g:go_highlight_functions'*
  1300. Highlight function and method declarations.
  1301. >
  1302. let g:go_highlight_functions = 0
  1303. <
  1304. *'g:go_highlight_function_arguments'*
  1305. Highlight the variable names in arguments and return values in function
  1306. declarations. Setting this implies the functionality from
  1307. |'g:go_highlight_functions'|.
  1308. >
  1309. let g:go_highlight_function_arguments = 0
  1310. <
  1311. *'g:go_highlight_function_calls'*
  1312. Highlight function and method calls.
  1313. >
  1314. let g:go_highlight_function_calls = 0
  1315. <
  1316. *'g:go_highlight_types'*
  1317. Highlight struct and interface names.
  1318. >
  1319. let g:go_highlight_types = 0
  1320. <
  1321. *'g:go_highlight_fields'*
  1322. Highlight struct field names.
  1323. >
  1324. let g:go_highlight_fields = 0
  1325. <
  1326. *'g:go_highlight_build_constraints'*
  1327. Highlights build constraints.
  1328. >
  1329. let g:go_highlight_build_constraints = 0
  1330. <
  1331. *'g:go_highlight_generate_tags'*
  1332. Highlight go:generate directives.
  1333. >
  1334. let g:go_highlight_generate_tags = 0
  1335. <
  1336. *'g:go_highlight_string_spellcheck'*
  1337. Highlight spelling errors in strings when |spell| is enabled.
  1338. >
  1339. let g:go_highlight_string_spellcheck = 1
  1340. <
  1341. *'g:go_highlight_format_strings'*
  1342. Highlight printf-style formatting verbs inside string literals.
  1343. >
  1344. let g:go_highlight_format_strings = 1
  1345. <
  1346. *'g:go_highlight_variable_declarations'*
  1347. Highlight variable names in variable declarations (`x` in ` x :=`).
  1348. >
  1349. let g:go_highlight_variable_declarations = 0
  1350. <
  1351. *'g:go_highlight_variable_assignments'*
  1352. Highlight variable names in variable assignments (`x` in `x =`).
  1353. >
  1354. let g:go_highlight_variable_assignments = 0
  1355. <
  1356. ==============================================================================
  1357. *gohtmltmpl* *ft-gohtmltmpl-syntax*
  1358. *gotexttmpl* *ft-gotexttmpl-syntax*
  1359. Go template syntax~
  1360. The `gotexttmpl` 'filetype' provides syntax highlighting and indentation for
  1361. Go's `text/template` package.
  1362. The `gohtmltmpl` filetype is for use with the `html/template` package and is
  1363. identical to `gotexttmpl` except that it will also load the standard `html`
  1364. filetype.
  1365. The `gohtmltmpl` filetype is automatically set for `*.tmpl` files; the
  1366. `gotexttmpl` is never automatically set and needs to be set manually.
  1367. ==============================================================================
  1368. DEBUGGER *go-debug*
  1369. Vim-go comes with a special "debugger mode". This starts a `dlv` process in
  1370. the background and provides various commands to communicate with it.
  1371. This debugger is similar to Visual Studio or Eclipse and has the following
  1372. features:
  1373. * Show stack trace and jumps.
  1374. * List local variables.
  1375. * List function arguments.
  1376. * Expand values of struct or array/slice.
  1377. * Show balloon on the symbol.
  1378. * Show output of stdout/stderr.
  1379. * Toggle breakpoint.
  1380. * Stack operation continue/next/step out.
  1381. This feature requires Vim 8.0.0087 or newer with the |+job| feature. Neovim
  1382. does _not_ work (yet).
  1383. This requires Delve 1.0.0 or newer, and it is recommended to use Go 1.10 or
  1384. newer, as its new caching will speed up recompiles.
  1385. *go-debug-intro*
  1386. GETTING STARTED WITH THE DEBUGGER~
  1387. Use |:GoDebugStart| to start the debugger. The first argument is the package
  1388. name, and any arguments after that will be passed on to the program; for
  1389. example:
  1390. >
  1391. :GoDebugStart . -someflag value
  1392. <
  1393. This may take few seconds. After the code is compiled you'll see three new
  1394. windows: the stack trace on left side, the variable list on the bottom-left,
  1395. and program output at the bottom.
  1396. You can add breakpoints with |:GoDebugBreakpoint| (<F9>) and run your program
  1397. with |:GoDebugContinue| (<F5>).
  1398. The program will halt on the breakpoint, at which point you can inspect the
  1399. program state. You can go to the next line with |:GoDebugNext| (<F10>) or step
  1400. in with |:GoDebugStep| (<F11>).
  1401. The variable window in the bottom left (`GODEBUG_VARIABLES`) will display all
  1402. local variables. Struct values are displayed as `{...}`, array/slices as
  1403. `[4]`. Use <CR> on the variable name to expand the values.
  1404. The `GODEBUG_OUTPUT` window displays output from the program and the Delve
  1405. debugger.
  1406. The `GODEBUG_STACKTRACE` window can be used to jump to different places in the
  1407. call stack.
  1408. When you're done use |:GoDebugStop| to close the debugging windows and halt
  1409. the `dlv` process, or |:GoDebugRestart| to recompile the code.
  1410. *go-debug-commands*
  1411. DEBUGGER COMMANDS~
  1412. Only |:GoDebugStart| and |:GoDebugBreakpoint| are available by default; the
  1413. rest of the commands and mappings become available after starting debug mode.
  1414. *:GoDebugStart*
  1415. :GoDebugStart [pkg] [program-args]
  1416. Start the debug mode for [pkg]; this does several things:
  1417. * Start `dlv debug` for [pkg], or `dlv test` if the current buffer's
  1418. filename ends with `_test.go`.
  1419. * Setup the debug windows according to |'g:go_debug_windows'|.
  1420. * Make the `:GoDebug*` commands and `(go-debug-*)` mappings available.
  1421. The current directory is used if [pkg] is empty. Any other arguments will
  1422. be passed to the program.
  1423. Use `-test.flag` to pass flags to `go test` when debugging a test; for
  1424. example `-test.v` or `-test.run TestFoo`
  1425. Use |:GoDebugStop| to stop `dlv` and exit debugging mode.
  1426. *:GoDebugRestart*
  1427. :GoDebugRestart
  1428. Stop the program (if running) and restart `dlv` to recompile the package.
  1429. The current window layout and breakpoints will be left intact.
  1430. *:GoDebugStop*
  1431. *(go-debug-stop)*
  1432. :GoDebugStop
  1433. Stop `dlv` and remove all debug-specific commands, mappings, and windows.
  1434. *:GoDebugBreakpoint*
  1435. *(go-debug-breakpoint)*
  1436. :GoDebugBreakpoint [linenr]
  1437. Toggle breakpoint for the [linenr]. [linenr] defaults to the current line
  1438. if it is omitted. A line with a breakpoint will have the
  1439. {godebugbreakpoint} |:sign| placed on it. The line the program is
  1440. currently halted on will have the {godebugcurline} sign.
  1441. *hl-GoDebugCurrent* *hl-GoDebugBreakpoint*
  1442. A line with a breakpoint will be highlighted with the {GoDebugBreakpoint}
  1443. group; the line the program is currently halted on will be highlighted
  1444. with {GoDebugCurrent}.
  1445. Mapped to <F9> by default.
  1446. *:GoDebugContinue*
  1447. *(go-debug-continue)*
  1448. :GoDebugContinue
  1449. Continue execution until breakpoint or program termination. It will start
  1450. the program if it hasn't been started yet.
  1451. Mapped to <F5> by default.
  1452. *:GoDebugNext*
  1453. *(go-debug-next)*
  1454. :GoDebugNext
  1455. Advance execution by one line, also called "step over" by some other
  1456. debuggers.
  1457. It will behave as |:GoDebugContinue| if the program isn't started.
  1458. Mapped to <F10> by default.
  1459. *:GoDebugStep*
  1460. *(go-debug-step)*
  1461. :GoDebugStep
  1462. Advance execution by one step, stopping at the next line of code that will
  1463. be executed (regardless of location).
  1464. It will behave as |:GoDebugContinue| if the program isn't started.
  1465. Mapped to <F11> by default.
  1466. *:GoDebugStepOut*
  1467. *(go-debug-stepout)*
  1468. :GoDebugStepOut
  1469. Run all the code in the current function and halt when the function
  1470. returns ("step out of the current function").
  1471. It will behave as |:GoDebugContinue| if the program isn't started.
  1472. *:GoDebugSet*
  1473. :GoDebugSet {var} {value}
  1474. Set the variable {var} to {value}. Example:
  1475. >
  1476. :GoDebugSet truth 42
  1477. <
  1478. This only works for `float`, `int` and variants, `uint` and variants,
  1479. `bool`, and pointers (this is a `delve` limitation, not a vim-go
  1480. limitation).
  1481. *:GoDebugPrint*
  1482. *(go-debug-print)*
  1483. :GoDebugPrint {expr}
  1484. Print the result of a Go expression.
  1485. >
  1486. :GoDebugPrint truth == 42
  1487. truth == 42 true
  1488. <
  1489. Mapped to <F6> by default, which will evaluate the <cword> under the
  1490. cursor.
  1491. *go-debug-settings*
  1492. DEBUGGER SETTINGS~
  1493. *'g:go_debug_windows'*
  1494. Controls the window layout for debugging mode. This is a |dict| with three
  1495. possible keys: "stack", "out", and "vars"; the windows will created in that
  1496. order with the commands in the value.
  1497. A window will not be created if a key is missing or empty.
  1498. Defaults:
  1499. >
  1500. let g:go_debug_windows = {
  1501. \ 'stack': 'leftabove 20vnew',
  1502. \ 'out': 'botright 10new',
  1503. \ 'vars': 'leftabove 30vnew',
  1504. \ }
  1505. <
  1506. Show only variables on the right-hand side: >
  1507. let g:go_debug_windows = {
  1508. \ 'vars': 'rightbelow 60vnew',
  1509. \ }
  1510. <
  1511. *'g:go_debug_address'*
  1512. Server address `dlv` will listen on; must be in `hostname:port` format.
  1513. Defaults to `127.0.0.1:8181`:
  1514. >
  1515. let g:go_debug_address = '127.0.0.1:8181'
  1516. <
  1517. ==============================================================================
  1518. FAQ TROUBLESHOOTING *go-troubleshooting*
  1519. I get "not an editor command" error when I invoke :GoXXX~
  1520. This happens if vim-go is not installed properly. Be sure you have added this
  1521. line into your vimrc:
  1522. >
  1523. filetype plugin indent on
  1524. <
  1525. I get a "command not found" error when I invoke :GoXXX~
  1526. If you try to call |:GoDef|, |:GoInfo| and get a command not found, check that
  1527. you have the binaries installed by using |:GoInstallBinaries|.
  1528. Before opening vim, check your current $PATH:
  1529. >
  1530. echo $PATH
  1531. <
  1532. After opening vim, run `:echo $PATH`, the output must be your current `$PATH`
  1533. plus `$GOPATH/bin` (the location where |:GoInstallBinaries| installed the
  1534. binaries).
  1535. *go-guru-scope*
  1536. What is the guru scope and how do I set it?~
  1537. Many vim-go commands use the `guru` commandline tool to get information. Some
  1538. `guru` commands require an expensive analysis of the source code. To still get
  1539. a reasonable amount of performance `guru` limits this analysis to a selected
  1540. list of packages. This is known as the "guru scope".
  1541. The default is to use the package the curent buffer belongs to, but this may
  1542. not always be correct. For example for the file `guthub.com/user/pkg/a/a.go`
  1543. the scope will be set to `github.com/user/pkg/a`, but you probably want
  1544. `github.com/user/pkg`
  1545. Guessing what package(s) you do want is not easy so you may need to set this
  1546. manually, usually from an |autocommand|:
  1547. >
  1548. autocmd BufRead /home/martin/go/src/github.com/user/pkg/*.go
  1549. \ :GoGuruScope github.com/user/pkg
  1550. <
  1551. If you have a lot of packages with the same prefix (`github.com/user`) you can
  1552. use a single autocommand:
  1553. >
  1554. autocmd BufRead /home/martin/go/src/*.go
  1555. \ let s:tmp = matchlist(expand('%:p'),
  1556. \ '/home/martin/go/src/\(github.com/user/[^/]\+\)')
  1557. \| if len(s:tmp) > 1 | exe 'silent :GoGuruScope ' . s:tmp[1] | endif
  1558. \| unlet s:tmp
  1559. <
  1560. Also see |:GoGuruScope| and |'g:go_guru_scope'|.
  1561. Vim becomes slow while editing Go files~
  1562. This is usually caused by `g:go_highlight_*` options. Try disabling them if
  1563. you've enabled some of them.
  1564. Other common culprits are |'g:go_auto_sameids'| and |go#statusline#Show()|.
  1565. I get errors when using GoInstallBinaries~
  1566. If you see errors like this:
  1567. >
  1568. Error installing golang.org/x/tools/cmd/goimports
  1569. <
  1570. that means your local Go setup is broken or the remote website is down. For
  1571. example sometimes code.google.com times out. To test, just execute a simple
  1572. `go get`:
  1573. >
  1574. go get golang.org/x/tools/cmd/goimports
  1575. <
  1576. You'll see a more detailed error. If this works, vim-go will work too.
  1577. I want to use a different binary name than "go", can I do this?~
  1578. There is no way to directly configure the binary name; but you can use a
  1579. wrapper script; for example if you would like to run `goapp` instead of `go`:
  1580. 1. In `~/gobin/go` (remember to make it executable):
  1581. >
  1582. #!/bin/sh
  1583. # Remove gobin from PATH and run goapp.
  1584. PATH=${PATH#$HOME/gobin} goapp "$@"
  1585. <
  1586. 2. Start Vim with `~/gobin` as the first `PATH` entry so it will use the
  1587. wrapper script:
  1588. >
  1589. PATH="$HOME/gobin/:$PATH" vim
  1590. <
  1591. Alternatively you you could set `$PATH` in your vimrc with an |:autocmd|.
  1592. How do I use vim-go with syntastic?~
  1593. Sometimes when using both `vim-go` and `syntastic` Vim will start lagging
  1594. while saving and opening files. The following fixes this:
  1595. >
  1596. let g:syntastic_go_checkers = ['golint', 'govet']
  1597. let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
  1598. <
  1599. If you want to add errcheck you can use gometalinter as a wrapper
  1600. >
  1601. let g:syntastic_go_checkers = ['golint', 'govet', 'gometalinter']
  1602. let g:syntastic_go_gometalinter_args = ['--disable-all', '--enable=errcheck']
  1603. let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
  1604. <
  1605. Another issue with `vim-go` and `syntastic` is that the location list window
  1606. that contains the output of commands such as `:GoBuild` and `:GoTest` might
  1607. not appear. To resolve this:
  1608. >
  1609. let g:go_list_type = "quickfix"
  1610. <
  1611. How do I run focused ginkgo tests?~
  1612. You must set this environment variable in your `.vimrc`:
  1613. >
  1614. let $GINKGO_EDITOR_INTEGRATION = "true"
  1615. <
  1616. Using with NeoVim~
  1617. Note: Neovim currently is not a first class citizen for vim-go. You are free
  1618. to open bug, however I'm not using Neovim so it's hard for me to test it.
  1619. vim-go might not work well as good as in Vim. I'm happy to accept pull
  1620. requests or very detailed bug reports. If you're interested to improve the
  1621. state of Neovim in vim-go you're always welcome!
  1622. Run `:GoRun` in a new tab, horizontal split or vertical split terminal
  1623. >
  1624. au FileType go nmap <leader>rt <Plug>(go-run-tab)
  1625. au FileType go nmap <leader>rs <Plug>(go-run-split)
  1626. au FileType go nmap <leader>rv <Plug>(go-run-vertical)
  1627. <
  1628. By default new terminals are opened in a vertical split. To change it
  1629. >
  1630. let g:go_term_mode = "split"
  1631. >
  1632. ==============================================================================
  1633. DEVELOPMENT *go-development*
  1634. vim-go supports test files written in VimScript; the way they're run is
  1635. roughly similar to Go tests:
  1636. - A `*.vim` file has a corresponding `*_test.vim`.
  1637. - All functions starting with `Test_` are run as test.
  1638. - A test is considered to be "failed" if |v:errors| has any entries. You can
  1639. use one of the |test-functions| to set this, or append to it directly.
  1640. A simple example:
  1641. >
  1642. function Test_run_fmt()
  1643. call assert_equal(expected, actual)
  1644. ...
  1645. endfunction
  1646. <
  1647. To run tests vim-go comes with three small helper scripts:
  1648. `scripts/install-vim` Install a pristine Vim to `/tmp/vim-go-test/`.
  1649. `scripts/run-vim` Run a Vim version from `/tmp/vim-go-test/`.
  1650. `scripts/test` Run all tests with a Vim from `/tmp/vim-go-test/`.
  1651. All scripts accept a Vim version as the first argument, which can be
  1652. `vim-7.4`, `vim-8.0`, or `nvim`. You will need to install a Vim version with
  1653. `install-vim` before you can use `run-vim` or `test`.
  1654. You can install and test all Vim versions by running `make`.
  1655. ==============================================================================
  1656. DONATION *go-donation*
  1657. People have asked for this for a long time, now you can be a fully supporter
  1658. by being a patreon at: https://www.patreon.com/fatih
  1659. By being a patron, you are enabling vim-go to grow and mature, helping me to
  1660. invest in bug fixes, new documentation, and improving both current and future
  1661. features. It's completely optional and is just a direct way to support
  1662. vim-go's ongoing development. Thanks!
  1663. Check it out: https://www.patreon.com/fatih
  1664. ==============================================================================
  1665. CREDITS *go-credits*
  1666. * Go Authors for official Vim plugins.
  1667. * Gocode, Godef, Golint, Guru, Goimports, Errcheck projects and authors of
  1668. those projects.
  1669. * Other vim-plugins, thanks for inspiration (vim-golang, go.vim, vim-gocode,
  1670. vim-godef).
  1671. * vim-go contributors: https://github.com/fatih/vim-go/graphs/contributors.
  1672. vim: ft=help tw=78 et ts=2 sw=2 sts=2 norl