Question

I am trying to index my tests with ctags so that I can jump around easier with the CtrlP vim plugin. The tests are in coffee script. This is what I have in my ~/.ctags config to find the describe blocks.

--regex-coffee=/^[ \t]*(describe+[ \t]+\"(.+?)\")+[ ,]+*->.*$/\1/t,test/

It finds the describe blocks ok, and this is what the ctags file looks like

User_resource_spec.coffee   tests/e2e/User_resource_spec.coffee 1;" F
assert  tests/e2e/User_resource_spec.coffee /^assert = require("assert")$/;"    v
describe "Create User"  tests/e2e/User_resource_spec.coffee /^describe "Create User", ->$/;"    t
describe "Users"    tests/e2e/User_resource_spec.coffee /^  describe "Users", ->$/;"    t
should  tests/e2e/User_resource_spec.coffee /^should = require("should")$/;"    v

The problem I have is that when I do

:tag describe "Create User"

it says that the tag isn't found. All the other tags work right. If I edit the tags file and change the

describe "Create User"

to just

describe 

then it works again. My guess is that it isn't working because of the whitespace and quotes.

Something weird though is that when I put periods and underscores instead of the spaces and get rid of the quotes it still doesn't work. As in I still can't jump to that tag. Yet Other tags with underscores and periods work just fine.

I can't change the tags to just "describe" though because I want to differentiate between the tests.

How do I get ctags to work with the spaces and quotes. Or if it is impossible to do that then what would be the best solution for jumping to specific mocha tests in vim.

Was it helpful?

Solution

You must escape the quotes:

:tag describe \"Create Users\"

That's a lot to type, why don't you simply do the following?

:tag des<Tab>

It would list describe \"Create Users\" and describe \"Users\" and also show you why :tag describe "Create Users" doesn't work (the non-escaped quotes).

Note that Vim uses whole word search by default for :tag and friends; you could use regex search to make the process a little more deterministic:

:tag /Crea<Tab>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top