Skip to content

romus204/go-tagger.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-tagger.nvim

A lightweight Neovim plugin to manage struct field tags in Go source files.

go-tagger.mp4

✅ 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

{
  "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

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:

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:

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.
:AddGoTags

You’ll be prompted:

tag(s): json,xml

Resulting output:

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.
:RemoveGoTags

Prompt:

tag: json

Result:

ID   int    `xml:"id"`
Name string `xml:"name"`

🔑 Example keybindings

vim.keymap.set("v", "<leader>at", ":AddGoTags<CR>", { desc = "Add Go struct tags", silent = true })
vim.keymap.set("v", "<leader>rt", ":RemoveGoTags<CR>", { desc = "Remove Go struct tags", silent = true })

About

Lightweight Neovim plugin to manage struct field tags in Go source files.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages