Search code examples
govimctags

ctags recognise const variable in go


I use vim+ctags to edit go code. I read the answer of ctag database for Go to configure my ctags, but it cann't recognise const variable definition, like this

const (
    kMyServiceName     = "serviceName"
    kIpForAnyNetDevice = "0.0.0.0"
)

I try --regex-Go=/const[ \t]+\((\s+([a-zA-Z_][a-zA-Z0-9_]+)[ \t]*=\S+)+/\1/v,var/ but it doesn't work.

Does anyone can share your solution?


Solution

  • Universal-ctags captures them.

    [yamato@master]~% cat /tmp/input.go
    cat /tmp/input.go
    const (
        kMyServiceName     = "serviceName"
        kIpForAnyNetDevice = "0.0.0.0"
    )
    [yamato@master]~% ~/var/ctags-github/ctags  --quiet --options=NONE -o - /tmp/input.go
    ~/var/ctags-github/ctags  --quiet --options=NONE -o - /tmp/input.go
    kIpForAnyNetDevice  /tmp/input.go   /^    kIpForAnyNetDevice = "0.0.0.0"$/;"    c
    kMyServiceName  /tmp/input.go   /^    kMyServiceName     = "serviceName"$/;"    c