gopher.nvim/README.md(view raw)
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 |
# gopher.nvim
Minimalistic plugin for Go development in Neovim written in Lua.
It's not an LSP tool, the main goal of this plugin add go tooling support in neovim.
## Install
Pre-dependency: [go](https://github.com/golang/go) (tested on 1.17 and 1.18)
```lua
use {
"olexsmir/gopher.nvim",
requires = { -- dependencies
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
}
```
Also, run `TSInstall go` if install the `go` parser if not installed yet.
## Config
By `.setup` function you can configure the plugin.
Note:
- Installer does not install the tool in user set path
```lua
require("gopher").setup {
commands = {
go = "go",
gomodifytags = "gomodifytags",
gotests = "~/go/bin/gotests", -- also you can set custom command path
impl = "impl",
},
}
```
## Features
1. Install requires go tools:
```vim
:GoInstallDeps
```
This will install next tools:
- [gomodifytags](https://github.com/fatih/gomodifytags)
- [impl](https://github.com/josharian/impl)
- [gotests](https://github.com/cweill/gotests)
2. Modify struct tags:
By default be added/removed `json` tag, if not set.
```vim
:GoTagAdd json " For add json tag
:GoTagRm yaml " For remove yaml tag
```
3. Run `go mod` command
```vim
:GoMod tidy " Runs `go mod tidy`
:GoMod init asdf " Runs `go mod init asdf`
```
4. Run `go get` command
Link can has a `http` or `https` prefix.
You can provide more that one package url.
```vim
:GoGet github.com/gorilla/mux
```
5. Interface implementation
Command syntax:
```vim
:GoImpl [receiver] [interface]
" Also you can put cursor on the struct and run:
:GoImpl [interface]
```
Example of usage:
```vim
" Example
:GoImpl r Read io.Reader
" or simply put your cursor in the struct and run:
:GoImpl io.Reader
```
6. Generate tests with [gotests](https://github.com/cweill/gotests)
Generate one test for spesific function/method
```vim
:GoTestAdd
```
Generate all tests for all functions/methods in current file
```vim
:GoTestsAll
```
Generate tests only for exported functions/methods in current file
```vim
:GoTestsExp
```
7. Run `go generate` command
```vim
" Run `go generate` in cwd path
:GoGenerate
" Run `go generate` for current file
:GoGenerate %
```
## Thanks
- [go.nvim](https://github.com/ray-x/go.nvim)
|