Home Download Buy Blog Forum Support

Auto-Pair Quotes

Re: Auto-Pair Quotes

Postby C0D312 on Sun Apr 15, 2012 10:55 pm

@shawnoster:

Add the following to your user keybindings:
Code: Select all
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "following_text", "operator": "regex_contains", "operand": "^[)\"'\\]\\};]", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false },
        { "key": "has_next_field", "operator": "equal", "operand": false }
    ]   
  }
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Auto-Pair Quotes

Postby quodlibet on Mon Apr 16, 2012 9:35 am

This binding eats tab when I try to indent blocks such as:

Code: Select all
* {
   color:fff;
}


Instead of indenting, hitting tab moves the caret after the `}`. Is there a workaround for this?

Edit:

If it doesn't complicate things too much I think it might also make sense for tabbing out of quotes to work with a select, so that:

* you can select: `TEXT`
* hit `"` to wrap it in quotes: `"TEXT"`
* and then hit TAB to place the caret after the last `"` (rather than replacing the selection with a tab)

But the indent issue is more pressing.
quodlibet
 
Posts: 543
Joined: Sat Jun 18, 2011 5:53 pm

Re: Auto-Pair Quotes

Postby MystickPhoenix on Mon Apr 16, 2012 5:18 pm

This used to drive me nuts too until I figured out one particular item: *ignore* the "paired" quote, bracket, brace, whatever that ST2 inserts for you. Just keep typing like you normally would and you won't end up with double closing things. So, if you want to type:
"test me now"
you would type quote, test me now, quote
and you'll get the above string and find yourself on the outside of the quotes.

It's basically just an easy way to make sure you don't miss a closing quote or bracket.
MystickPhoenix
 
Posts: 26
Joined: Tue Jan 24, 2012 4:36 pm

Re: Auto-Pair Quotes

Postby quodlibet on Mon Apr 16, 2012 5:59 pm

@MystickPhoenix I think that's the way you're supposed to used it, but if it's possible to get the tab functionality working well, I (think) I'd prefer it. Mashing the tab key is easier/faster than shift+anything.

I'm currently experimenting with auto-pairing asterisks when writing Markdown and I find shift+8 to be a particularly disrupting binding. But I'm nitpicking, of course.
quodlibet
 
Posts: 543
Joined: Sat Jun 18, 2011 5:53 pm

Re: Auto-Pair Quotes

Postby textisgood on Tue May 01, 2012 4:06 am

Is there any way to disable auto pairing, but still be able to quote the selected text with ' and "? They seem mostly unrelated, but disabling one disabled the other.

I also never understood auto pairing. Basically no time savings, but definitely can mess you up at times by inserting extra quotes where you don't want them.
textisgood
 
Posts: 9
Joined: Fri Oct 23, 2009 4:36 pm

Re: Auto-Pair Quotes

Postby quodlibet on Tue May 01, 2012 9:40 am

@textisgood

Auto-pairing quotes works via some rather ingenious key bindings (try searching for "auto-pair" in your default bindings file).

Just add these to your user key binding file for quoting selected text with `" and `':

Code: Select all
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"${0:$SELECTION}\""}, "context":
   [
      { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
   ]
},
{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'${0:$SELECTION}'"}, "context":
   [
      { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
   ]
},


Note that I've removed out the context that requires the "auto_match_enabled" setting to be true, which means that these will work regardless of your settings. Also, I pulled them from the default bindings file for Linux; I don't imagine there would be differences between OSs in this case, but I could be wrong.
quodlibet
 
Posts: 543
Joined: Sat Jun 18, 2011 5:53 pm

Re: Auto-Pair Quotes

Postby prmaple on Tue May 01, 2012 9:45 am

shawnoster wrote:What would make this work flow even better is the ability to "tab out" of the auto-matched quote/brace/bracket/ending mark. There is a plug-in for Visual Studio that does this and it's incredibly useful. When you get the point where you'd normally type another quote or right arrow you instead tab.

The productively comes from the fact that tabbing is much faster than either right-arrow or another closing character, many of which require a shift+combo. I think I've started one or two thread in these forums requeting this feature as have a few others. You don't know what you're missing until it's gone :)


Code: Select all
   { "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true},
     "context": [
      { "key": "setting.command_mode", "operand": false },
      { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
      { "key": "preceding_text", "operator": "regex_contains", "operand": "[^^]", "match_all": true},
      { "key": "following_text", "operator": "regex_contains", "operand": "(?:\"|\\)|\\]|\\}|\\>|')", "match_all": true}
     ]
   }
Find me
HTML5 Games: SNAKE! Tetris!
prmaple
 
Posts: 82
Joined: Sun Dec 25, 2011 11:06 am
Location: Melbourne

Re: Auto-Pair Quotes

Postby quodlibet on Tue May 01, 2012 10:00 am

I was about to post my own attempt to improve C0D312's binding, but @prmaple's looks more robust. Thanks for posting!
quodlibet
 
Posts: 543
Joined: Sat Jun 18, 2011 5:53 pm

Re: Auto-Pair Quotes

Postby itaiferber on Tue May 01, 2012 3:09 pm

Mine is a bit more complicated, but features a lot of behaviors that I like.

Code: Select all
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": true },
        { "key": "preceding_text", "operator": "not_regex_match", "operand": "[[:space:]]*", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^[\"'\\)\\}\\]]", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false },
        { "key": "has_next_field", "operator": "equal", "operand": false }
    ]
},
{ "keys": ["tab"], "command": "move", "args": {"by": "words", "forward": true}, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": true},
        { "key": "preceding_text", "operator": "not_regex_match", "operand": "[[:space:]]*", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^[.,:;]", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false },
        { "key": "has_next_field", "operator": "equal", "operand": false }
    ]
},
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": true},
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex", "match_all": true },
        { "key": "preceding_text", "operator": "not_regex_match", "operand": "[[:space:]]*", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^[$]", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false },
        { "key": "has_next_field", "operator": "equal", "operand": false }
    ]
}


The other keybindings I've found tend to not factor in whether the bracket or quote is at the beginning of the line, so they didn't work for me. I want
Code: Select all
^|"Hello!"
to become
Code: Select all
^    |"Hello"
instead of
Code: Select all
^"|Hello"
('^' is the start of the line, and '|' is the cursor position). When I'm at the beginning of the line, I almost always want to indent, so I've factored that in. I also use tab to skip over common punctuation, and in that case, I want to skip to the next word, not just one character to the right. And finally, I write quite a bit in LaTeX, so I added a special case for LaTeX's inline math.

Hopefully, this'll be of use to someone.
itaiferber
 
Posts: 15
Joined: Mon Apr 16, 2012 1:04 am

Re: Auto-Pair Quotes

Postby charlesroper on Fri May 11, 2012 12:41 pm

How might I tab out of a selection that I have wrapped with auto-pairs. Like this:

Code: Select all
here are some words


I place the cursor on "some" and hit Ctrl-D to select, then hit [" to wrap like so:

Code: Select all
here are ["some|"] words


The cursor is where the | is but the word some is still selected. Hitting tab would move past the closing quote:

Code: Select all
here are ["some"|] words


Hitting tab again would move past the closing square bracket:

Code: Select all
here are ["some"]| words


And if the cursor is here:

Code: Select all
here are ["|some"] words


The hitting tab would still move it past the closing quote as above:

Code: Select all
here are ["some"|] words


Possible?
charlesroper
 
Posts: 107
Joined: Thu Feb 18, 2010 7:30 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 27 guests