Sublime Forum

Can Tab key do this?

#1

1 feature I really found helpful in vscode while writing html codes was-

While writing attributes, a translucent caret appears outside the bracket (or outside the inverted commas depending on the code). After writing values in attribute, I just have to press tab and the caret goes to the translucent position (for example, outside the brackets).

This is really helpful as my fingers stretch too much for pressing the right arrow key on the keyboard to shift the caret rightwards after I work with each bracket (be it for/while loop, if/else, any maths equation… anything.). And making snippets won’t sove the problem as the use of brackets is very arbitrary.
Is there a setting to change it in preferences?

Basically after writing anything in the () paranthesis, I just press tab and the caret comes out of the brackets and I continue typing.

0 Likes

#2

From your previous posts, I presume you are asking snippets. $1/$2/… is what you want, specially, $0 is the last cursor position. https://docs.sublimetext.io/guide/extensibility/snippets.html#placeholders

0 Likes

#3

Thank you for the link sir.
I wanted to know if it is possible to take the caret from (here) to outside the paranthesis by pressing tab key.
Snippets would give me the specific code that I set. Is the above possible for each and every bracket?

0 Likes

#4

If my hint is not obvious enough, put $0 to wherever you would like your cursor to be after pressing a tab. If this is still not obvious enough, provide us your snippet.

0 Likes

#5

The snippet: (tab trigger- template)
include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(int i=l; i<r; ++i)
#define abd(i,r,l) for(int i=r; i>=l; --i)
#define qwer(a,b) for(auto &a:b)

const int mod=${1:0};

int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t–){
// int n$2; cin >> n; $3
cout << “\n”;
}
}

  1. I had to omit # in the beginning because the completions menu doesn’t open if I just press the tab trigger. So after pressing ‘#t’ it shows autocompletions. That’s why I deleted ‘#’. If there is a setting that I should be changing in preferences so that this issue is solved, please suggest sir.

  2. Here (in the snippets) the tab key works fine. Imagine writing a code and using () whenever required.
    Example- when I write if/else statements,

      if(caret here while writing condition)
    

After writing the condition,

       if() i want it to be here now

I’ll have to go to the right arrow key to take the caret out of the paranthesis. Wouldn’t it be better if tab key did the job because it is much easier to access it?!

I would be very grateful if you would solve these 2 things sir.

0 Likes

#6

In your snippet, you already use $1, $2, $3. So you just add $0 to where you want the cursor to be finally. E.g.,

  if($1)$0
0 Likes

#7

Thank you sir.

0 Likes