https://github.com/romus204/go-tagger.nvim
Lightweight Neovim plugin to manage struct field tags in Go source files.
https://github.com/romus204/go-tagger.nvim
Last synced: 2 months ago
JSON representation
Lightweight Neovim plugin to manage struct field tags in Go source files.
- Host: GitHub
- URL: https://github.com/romus204/go-tagger.nvim
- Owner: romus204
- License: mit
- Created: 2025-06-04T18:50:29.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-08-20T11:17:14.000Z (8 months ago)
- Last Synced: 2025-08-20T13:16:44.317Z (8 months ago)
- Language: Lua
- Homepage:
- Size: 13.7 KB
- Stars: 12
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim-sorted - romus204/go-tagger.nvim
- awesome-neovim - romus204/go-tagger.nvim - A lightweight plugin to manage struct field tags in Go files. (Programming Languages Support / Golang)
README
# go-tagger.nvim
A lightweight Neovim plugin to manage struct field tags in Go source files.
https://github.com/user-attachments/assets/a0295f98-7d15-4ab1-852c-8be877cb0fd7
✅ Features:
- Add new tags (`json`, `xml`, etc.) interactively
- Convert field names to `snake_case`,`camelCase`,`kebab-case`, `PascalCase`
- Preserve existing tags
- Skip unexported (private) fields by default
- Remove specific tags or all tags from selected lines
- **Visual mode support for multi-line editing**
---
## 📦 Installation
### [lazy.nvim](https://github.com/folke/lazy.nvim)
```lua
{
"romus204/go-tagger.nvim",
config = function()
require("go-tagger").setup({
skip_private = true, -- Skip unexported fields (starting with lowercase)
casing = "camelCase", -- Global casing setting
tags = { -- Per tag setting override
json = {
casing = "camelCase" -- json tags should use camelCase
},
xml = {
casing = "snake_case" -- xml tags should use snake_case
}
}
})
end,
}
```
### packer.nvim
```lua
use {
"romus204/go-tagger.nvim",
config = function()
require("go-tagger").setup({
skip_private = true, -- Skip unexported fields (starting with lowercase)
casing = "camelCase", -- Global casing setting
tags = { -- Per tag setting override
json = {
casing = "camelCase" -- json tags should use camelCase
},
xml = {
casing = "snake_case" -- xml tags should use snake_case
}
}
})
end,
}
```
---
## ⚙️ Configuration
Default config:
```lua
require("go-tagger").setup({
skip_private = true, -- Skip unexported fields (starting with lowercase)
casing = "snake_case", -- Global casing setting
tags = {} -- Per tag setting override
})
```
Example:
```lua
require("go-tagger").setup({
skip_private = false, -- NO Skip unexported fields (starting with lowercase)
casing = "camelCase", -- Global casing setting
tags = { -- Per tag setting override
json = {
casing = "camelCase" -- json tags should use camelCase
},
xml = {
casing = "snake_case" -- xml tags should use snake_case
}
}
})
```
---
## 🚀 Usage
### Visual Mode Support
You can use the plugin in **visual mode** to tag or untag multiple lines at once. Just select the fields and run one of the available commands.
---
## 🔧 Commands
### `:AddGoTags`
Adds tags to selected struct fields.
- Works in visual mode over one or more lines.
- Prompts you to enter tag names, separated by commas (e.g., `json,xml`).
- Ignores unexported fields if `skip_private = true`.
```vim
:AddGoTags
```
You’ll be prompted:
```
tag(s): json,xml
```
Resulting output:
```go
ID int `json:"id" xml:"id"`
Name string `json:"name" xml:"name"`
```
---
### `:RemoveGoTags`
Removes tags from selected struct fields.
- Works in visual mode over one or more lines.
- Prompts you to enter a tag name to remove (e.g., `json`).
- Leave input blank to remove **all tags**.
```vim
:RemoveGoTags
```
Prompt:
```
tag: json
```
Result:
```go
ID int `xml:"id"`
Name string `xml:"name"`
```
---
## 🔑 Example keybindings
```lua
vim.keymap.set("v", "at", ":AddGoTags", { desc = "Add Go struct tags", silent = true })
vim.keymap.set("v", "rt", ":RemoveGoTags", { desc = "Remove Go struct tags", silent = true })
```