How to do block comments in Gherkin? - syntax

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 + /

Related

How to highlight all occurrences of selected word in scintilla/scite?

In Notepad++, when select a word by double click or by cursor select, all other occurrences of the word will be selected.
What is the API to call to achieve this in Win32 (C++) platform.
Please checkout the "MatchMarker.cxx" file in SciTE source.
You can set
highlight.current.word=1
in SciTEUser.properties file which can be accessed from the menu Options > Open User Options File.
More options refers to https://www.scintilla.org/SciTEDoc.html .

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 ?

How do you set the default file extension for a syntax in Sublime Text 3?

I'm not asking about associating a syntax with a file extension, but about associating a file extension with a syntax. That is, setting the file extension suggested in the save file dialog after you create a new file, then set the syntax, then hit save.
You can change the extension in the save dialog, but it would be better not to have to do that every time.
For saving plain text files with a .txt extension by default, you can achieve this with a small plugin:
import sublime
import sublime_plugin
class DefaultPlainTextExtensionEventListener(sublime_plugin.EventListener):
def update_default_extension(self, view, syntax):
if syntax == 'Packages/Text/Plain text.tmLanguage':
view.settings().set('default_extension', 'txt')
elif view.settings().get('default_extension', None) == 'txt':
view.settings().erase('default_extension')
def on_new_async(self, view):
self.update_default_extension(view, view.settings().get('syntax'))
def on_post_text_command(self, view, command_name, args):
if command_name == 'set_file_type':
self.update_default_extension(view, args['syntax'])
elif command_name in ('paste', 'paste_and_indent'):
self.update_default_extension(view, view.settings().get('syntax'))
Note that we can't use the on_pre_save event because the file dialog has already been shown to the user by the point this is triggered, and the file name chosen.
The idea is that, when a new tab is created or the syntax is changed to Plain Text, it will set the default_extension setting to txt. If the syntax changes to something else, it will remove the default_extension.
For changing the default file extension for a syntax, it requires changing the .sublime-syntax file to re-order the file extensions set, so that the default one is first in the list.
(Using the default_extension referenced earlier is unreliable.)
So, for Markdown, you could do the following to change the default from .mdown to .md:
Install PackageResourceViewer if it is not already installed
Open the Command Palette
Type PRV: O
Select PackageResourceViewer: Open Resource
Select Markdown
Select Markdown.sublime-syntax
Find where it says:
file_extensions:
- mdown
- markdown
- markdn
- md
Change it so that md is at the top:
file_extensions:
- md
- mdown
- markdown
- markdn
Save the file
Then, when you create a new tab, set the syntax to Markdown and save it, it will default to the .md file extension.
Note that you could try to create an issue/PR at the relevant GitHub repo, if you believe that changing the default could benefit others too and want to see the repo maintainer's reaction.
Are you also trying to set, say, .txt. as the default file extension for when saving plaintext documents? I've looked around and as far as I've seen it's not currently possible to do so. Sadly the default Plain Text content type appears to be the only one that DOESN'T default to its specific .txt extension even though it exists in the Save as type dropdown in the Save As window:
I've seen the AdvancedNewFile plugin recommended as a way to work around this but I don't have any personal experience with it.

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 ?

Resources