Search code examples
sublimetext2code-snippets

How to create and use a custom snippet in Sublime Text 2 for Linux?


I read the similar posts that popped up on google, none of them had resolved the issue, so I'm asking this again.

I want to create a snippet for C++ file to initialize a new file with the following lines of code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long l;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > tii;
typedef vector<pair<int,int> > vec_pii;
#define fastinput ios_base::sync_with_stdio(false); cin.tie(false);
#define mp make_pair
#define setbits(n) __builtin_popcount((n))
#define pb push_back
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define sf(n) scanf("%lld",&(n))
#define pf(n) printf("%lld\n",(n))
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))

This is the snippet code that I came up with (doesn't work). Please correct the mistake and verify if it works.

<snippet>
    <content><![CDATA[
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long l;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > tii;
typedef vector<pair<int,int> > vec_pii;
#define fastinput ios_base::sync_with_stdio(false); cin.tie(false);
#define mp make_pair
#define setbits(n) __builtin_popcount((n))
#define pb push_back
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define sf(n) scanf("%lld",&(n))
#define pf(n) printf("%lld\n",(n))
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>newfile</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.cpp</scope>
</snippet>

Solution

  • Change
    <scope>source.cpp</scope>
    to
    <scope>source.c++</scope>


    You can use SublimeText's show_scope_name command or a plugin like ScopeHunter to find the correct scope name for your target documents & regions.