Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Surrounding lines with if() {...} ?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Zeblote
Tomato Guru

183 Posts

Posted - Jun 01 2018 :  05:46:38 AM  Show Profile  Reply with Quote
More of a question that support... just today I found some "surround with" feature of VA, but can't figure out how to use it correctly.

What's the quickest way to turn



into



?

feline
Whole Tomato Software

United Kingdom
18983 Posts

Posted - Jun 01 2018 :  06:11:43 AM  Show Profile  Reply with Quote
Go to the VA Snippet editor, and set the search fields to:

Scope = Private
Language = C++
Type = Surround With

in the list of snippets you should see three versions of "if", for this code you are looking for the line "if () { ... } if"

Select this one, which will have the body - assuming you have not edited this default snippet yet:

if ($end$)
{
    $selected$
}

and then set the "Surround With" field to "i" and accept the dialog. To use this snippet select the code you want to surround, and with the code selected press the letter "i", and this snippet will be triggered.

More generally, you can set a single character shortcut to trigger any snippet that uses $selected$ to trigger this snippet on selected text. $end$ is where the caret ends up after the snippet has been inserted.

zen is the art of being at one with the two'ness
Go to Top of Page

Zeblote
Tomato Guru

183 Posts

Posted - Jun 01 2018 :  06:58:06 AM  Show Profile  Reply with Quote
Ohh, I get it now! So that's what the little box is for... works great!

Now I'm sometimes triggering it accidentally though. Would it be possible to bind these to key combinations that you don't normally use when typing, like alt-i?
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18983 Posts

Posted - Jun 01 2018 :  10:14:04 AM  Show Profile  Reply with Quote
There are very few if any "simple" keyboard shortcuts that are not already taken by the IDE or VA. Alt + letter opens a menu if there is a matching menu item, and the menu items vary depending on the file type you have open. You can try a less commonly used key on the keyboard, but you still risk having the same problem.

Personally I have mapped the keyboard shortcut Ctrl+# (Text Editor) to the command VAssistX.VaSnippetInsert.

When I have selected a block of text I press Ctrl+#, and then scroll through the menu list of snippets using $selected$ until I get to the one I want. Simple and easy, and not something I tend to trigger by accident.

zen is the art of being at one with the two'ness
Go to Top of Page

Zeblote
Tomato Guru

183 Posts

Posted - Jun 01 2018 :  11:20:11 AM  Show Profile  Reply with Quote
Oh, I didn't know it was possible to bind a key for that. Have set it up
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Jun 01 2018 :  1:07:11 PM  Show Profile  Reply with Quote
For the Surround With field, I've found that using upper-case letters is more useful than lower-case letters.
T -> wrap in try/catch block
N -> wrap in namespace
R -> wrap in raw-string literal delimiters
F -> wrap in for loop
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000