Search code examples
c++sublimetext2code-snippets

Creating c++ namespace like snippets in subime text


I am looking for a way to create some c++ namespace like snippet in sublime text2 which should behave like this:

assuming we have a namespace called "fu" which contains "vector","Point,"Mat". I create snippets with following tabtriggers:

<tabTrigger>fu::vector</tabTrigger>
<tabTrigger>fu::Point</tabTrigger>
<tabTrigger>fu::Mat</tabTrigger>

When I now type "fu" the selection box with all 3 snippets appears (which is perfect), but as soon as I type "::" they all disappear.Why is that? Even when I type "fu::vecto" there is no selection for the snippet. It seams that the double point escapes all snippets triggers.

I really need the behavior when I type "::" which should me show all definition in the specific namespace.

Is that somehow possible? Thank you in advance for your time.


Solution

  • Sublime Text 2 considers the : character to be a word separator, so to Sublime Text, typing a : is just the same as typing a space to separate words. Ergo, it cuts off autocompletion.

    You can make :s in snippets work in the way you want them to by adding this line to your user preferences file (Preferences -> Settings - User. Make sure to fix commas if you need to):

    "word_separators": "./\\()\"'-,.;<>~!@#$%^&*|+=[]{}`~?",
    

    That's just the word_separators value from the default settings file, but with the : taken out.

    If you only want Sublime Text to ignore : in C++, add the line to your C++ preferences file instead (Open a C++ file -> Preferences -> Settings - More -> Syntax Specific - User).