VS shortcuts - create block - visual-studio

VS2010 or later - is there a way to 'block' a block, put it in a {}?
None shortcut-key references I've met seem to mention this (nor have I found it in the menus, to tell the truth), but it seems to be something trivial.
Alternatively - can I create such a thing myself (macro?)?

You can use snippets to surround code with Ifs or Trys you can assign these to keys.

For C# you can create your own snippet similar to ones that shows up when you chose "surround with" from right click menu (Ctrl+K,S) like "do" for "forr".
Snippet location for "do" - ...\Program Files\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#\do.snippet
Your snippet would probably look like
<Code Language="csharp"><![CDATA[do
{
$selected$ $end$
}]]>
</Code>

Related

Sublime Text 2 loading all shell scripts as plain text [duplicate]

I'd like Sublime 2 editor to treat *.sbt files (to highlight syntax) as Scala language, same as *.scala, but I can't find where to set this up. Do you happen to know?
In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command:
View -> Syntax -> Open all with current extension as ...
I've found the answer (by further examining the Sublime 2 config files structure):
I was to open
~/.config/sublime-text-2/Packages/Scala/Scala.tmLanguage
And edit it to add sbt (the extension of files I want to be opened as Scala code files) to the array after the fileTypes key:
<dict>
<key>bundleUUID</key>
<string>452017E8-0065-49EF-AB9D-7849B27D9367</string>
<key>fileTypes</key>
<array>
<string>scala</string>
<string>sbt</string>
<array>
...
PS: May there be a better way, something like a right place to put my customizations (insted of modifying packages themselves), I'd still like to know.
I put my customized changes in the User package:
*nix: ~/.config/sublime-text-2/Packages/User/Scala.tmLanguage
*Windows: %APPDATA%\Sublime Text 2\Packages\User\Scala.tmLanguage
Which also means it's in JSON format:
{
"extensions":
[
"sbt"
]
}
This is the same place the
View -> Syntax -> Open all with current extension as ...
menu item adds it (creating the file if it doesn't exist).
For ST3
$language = "language u wish"
If exists, open ~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings
else just create it.
And set
{
"extensions":
[
"*yourextension*"
]
}
This way allows you to enable syntax for composite extensions (e.g. sql.mustache, js.php, etc ... )
There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.
There is a quick method to set the syntax:
Ctrl+Shift+P,then type in the input box
ss + (which type you want set)
eg: ss html +Enter
and ss means "set syntax"
it is really quicker than check in the menu's checkbox.
I know this topic is old now, but let me state a new approach, some people might find this easy to understand and do.
Open Sublime Text(make sure you have Package Control installed and ready in your Sublime Text):
Ctrl+Shift+P(or Cmd+Shift+P for MacOS guys)
Type "PRV"(Package Resource Viewer), select the one ending with :Open Resource
Type "SCALA"/"scala" and press Enter
Type Scala.sublime-syntax and press Enter and press Esc to close the
open list
Now in Scala.sublime-syntax goto the section file_extensions: and add your file extension sbt(like - sbt) in the end of that section
Save and close the file and restart Sublime Text, you'll now have
Scala syntax highlighting for your custom .sbt extension. Same steps can be done with any file type like XML, PHP, HTML, JS etc.
Pretty easy to follow, right ?

Resharper "No Suggestions" box

I noticed that Resharper adds "No Suggestion" box on new properties in C# classes. Like this:
This "No Suggestion" box does not add anything to the code, only obstructs lines of code below - and that is an annoyance.
Any way to make Resharper not show this box?
You can edit the prop Live Template and remove the macro associated with the $NAME$ variable of the property.
What ReSharper is trying to do is suggest a name for the property, based on the type. If it's a bool property, there's not much it can suggest, but if it's a complex type, such as Address, then it can suggest a name such as Address. Also, if it's a List<Address>, ReSharper will suggest Addresses or List. So, it can be useful.
However, it isn't terribly helpful to show No suggestions - it might be nicer to just not show anything if the list is empty. I've added a feature request you can vote on and track: RSRP-453668

Assign code snippet to keyboard shortcut in Visual Studio

Anyone knows how to assign key shortcut to specific code snippet?
I would like to assign for instance CTRL+K,CTRL+J to a #region snippet.
Therefore by able to:
select text,
press CTRL+K,CTRL+J =>
selected text would be surrounded with #region .. #endregion.
I hate when I have to take my hands out of keyboard for more time than necessary:).
EDIT: For more understanding, I am asking how to bind key shortcut directly to SPECIFIC snippet. Opening snippet selector wont work for me. If I have to search through all my snippets to get to a the #region one, its worse then writting all its code by myself.
Thx for any suggestions.
Type a < and then type your snippet shorcut(your XML file Name) and then press tab.
you can get more info from this link
https://learn.microsoft.com/en-us/visualstudio/xml-tools/how-to-use-xml-snippets?view=vs-2017
for example i have a code snippet which i've set xml file name and its shortcut to flog
when i want to use it directly to my code i do like this:
<flog and press tab it Works.
The closest solution I've found for this is to copy the intended snippet to your local snippets directory.
e.g. For VS-2015:
%Userprofile%\Documents\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets
Then open it in a text editor and change the shortcut to something quick and simple such as '1'.
Now to use it, all you need to do is press Ctrl+K+S > Enter > 1 > Enter
Additionally, you can make it even quicker by changing the hotkey for the surround-with command.
(Tools > Options > Keyboard > Edit.SurroundWith)
I think you may want to try adding a <Shortcut> tag inside your MySnippet.snippet file
<Header>
<Title>Square Root</Title>
<Author>Myself</Author>
<Description>Calculates the square root of 16.</Description>
<Shortcut>sqrt</Shortcut>
</Header>
For details check out : https://learn.microsoft.com/en-us/visualstudio/ide/walkthrough-creating-a-code-snippet?view=vs-2019#description-and-shortcut-fields
To add a shortcut, add a Shortcut element within the Header element
For me the fastest solution was to Import a Folder named "1", then Add the snippet (my name was "block") and mark it in the 1-Folder.
Then i can insert the snippet by
<Ctrl+K,X> + <Enter> + <Enter>
First Enter chooses 1 (the Folder with MY snippets) and the second Enter chooses my most used snippet (must be alphabetically first)

How to customise file type to syntax associations in Sublime Text?

I'd like Sublime 2 editor to treat *.sbt files (to highlight syntax) as Scala language, same as *.scala, but I can't find where to set this up. Do you happen to know?
In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command:
View -> Syntax -> Open all with current extension as ...
I've found the answer (by further examining the Sublime 2 config files structure):
I was to open
~/.config/sublime-text-2/Packages/Scala/Scala.tmLanguage
And edit it to add sbt (the extension of files I want to be opened as Scala code files) to the array after the fileTypes key:
<dict>
<key>bundleUUID</key>
<string>452017E8-0065-49EF-AB9D-7849B27D9367</string>
<key>fileTypes</key>
<array>
<string>scala</string>
<string>sbt</string>
<array>
...
PS: May there be a better way, something like a right place to put my customizations (insted of modifying packages themselves), I'd still like to know.
I put my customized changes in the User package:
*nix: ~/.config/sublime-text-2/Packages/User/Scala.tmLanguage
*Windows: %APPDATA%\Sublime Text 2\Packages\User\Scala.tmLanguage
Which also means it's in JSON format:
{
"extensions":
[
"sbt"
]
}
This is the same place the
View -> Syntax -> Open all with current extension as ...
menu item adds it (creating the file if it doesn't exist).
For ST3
$language = "language u wish"
If exists, open ~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings
else just create it.
And set
{
"extensions":
[
"*yourextension*"
]
}
This way allows you to enable syntax for composite extensions (e.g. sql.mustache, js.php, etc ... )
There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.
There is a quick method to set the syntax:
Ctrl+Shift+P,then type in the input box
ss + (which type you want set)
eg: ss html +Enter
and ss means "set syntax"
it is really quicker than check in the menu's checkbox.
I know this topic is old now, but let me state a new approach, some people might find this easy to understand and do.
Open Sublime Text(make sure you have Package Control installed and ready in your Sublime Text):
Ctrl+Shift+P(or Cmd+Shift+P for MacOS guys)
Type "PRV"(Package Resource Viewer), select the one ending with :Open Resource
Type "SCALA"/"scala" and press Enter
Type Scala.sublime-syntax and press Enter and press Esc to close the
open list
Now in Scala.sublime-syntax goto the section file_extensions: and add your file extension sbt(like - sbt) in the end of that section
Save and close the file and restart Sublime Text, you'll now have
Scala syntax highlighting for your custom .sbt extension. Same steps can be done with any file type like XML, PHP, HTML, JS etc.
Pretty easy to follow, right ?

How to do block comments in Gherkin?

In gherkin syntax (used by Cucumber and SpecFlow, I can comment out a line by prefixing it with '#'
Is there any way to block-comment multiple lines?
It is not supported by Gherkin, so you have to prefix all lines with #.
If you use the SpecFlow Visual Studio extension (v1.9.2) you can simply select the lines and toggle them into comments and back. The default shortcuts are Ctrl+K,C to comment and Ctrl+K,U to uncomment.
You can also "workaround" this problem in Visual Studio using the multi-line editing feature. (See http://weblogs.asp.net/scottgu/archive/2010/04/26/box-selection-and-multi-line-editing-with-vs-2010.aspx). You just have to select the beginning of the lines with holding ALT and using the mouse. Using this feature you can type in all the selected lines at the same time. You can also remove all of them similarly, selecting all the # characters for deletion.
Yes, there is. It's called PyStrings type comments. See example at http://docs.behat.org/guides/1.gherkin.html#pystrings.
It will work if you use it just after Feature or Scenario and some other elements.
Feature: my feature
""" some block comment
still block comment
""" end of block comment
Scenario: my feature
""" some block comment
still block comment
""" end of block comment
One the other hand it will not work if you want to comment out some steps.
I think you can configure your IDE to comment out a line on standard key combination. For example IntelliJ recognizes *.feature files and allows to comment out line out of the box. The same possible to do with Notepad++ or even VS.
Single line comment : #
Mutli line comment :
Starts with """
Ends with """
In Eclipse, for commenting single/multiple lines of Gherkin feature file content, we can also do the following.
Add new file association
Windows > Preferences > General > Editors> File Associations > File types: > Add...
and add a new file type as *.feature
Associate an editor for new file type
Associated Editors > > Add...
add Properties File Editor (Default).
Now reopen the file if it's open and it will open in Properties File Editor instead of Text editor.
Doing this allows me select any number of lines and comment-out using the common commenting shortcut Ctrl+Shift+C
Use CTRL + /
It works great. Multiple line comment
For commenting :
Single Line --> #
Multiple Line --> """
Use Command key + '?' key to comment multiple lines for cucumber scripts in MAC.
There's no block commenting in Gherkin, however you can comment multiple lines at once by selecting that block and hitting ctrl + /
You could achieve it by selecting all the lines that you want to comment and then pressing "Ctrl + plus/equals key + /" keys in eclipse.
I don't think it's supported, actually. I have been doing Cucumber related work for about 2 years now and I never seen it.
You'll have to do lot of #-lines ;).
I would start reading the great wiki on github (https://github.com/cucumber/cucumber/wiki/Gherkin)
In Eclipse, for commenting single/multiple lines of Gherkin feature file content, we can also do the following.
Add new file association
Windows > Preferences > General > Editors> File Associations > File types: > Add...
and add a new file type as *.feature
Associate an editor for new file type
Associated Editors > > Add...
add Properties File Editor (Default).
Now reopen the file if it's open and it will open in Properties File Editor instead of Text editor.
Doing this allows me select any number of lines and comment-out using the common commenting shortcut Ctrl+Shift+C
Well, I have so far used # to comment the test steps. If you use this, you should individually comment out each and every line, scenarios and examples which ever applicable. Though this is not recommended, still, I dont see anything similar supported in gherkin yet.
Select all the lines you want to comment and press cmd+shift+c.
There's no block commenting in Gherkin, however you can comment multiple lines at once by selecting that block and hitting ctrl + /

Resources