Gherkin Syntax Highlighting in Notepad++

Notepad++ is an excellent text editor for Windows. It is free, lightweight, feature-rich, and extendable. It can handle just about any programming language out there. I use it all the time, especially for config files and quick edits that don’t require a bulky IDE. Seriously, if you don’t have it, download it now. (Not a Windows user? Check out Gherkin Syntax Highlighting in Atom.)

One of the nifty features in Notepad++ is User Defined Language, which allows users to customize the syntax highlighting for any language. This is invaluable if you use an obscure language or even create your own. To access this feature in version 7.2.2, simply navigate to the Language menu option and choose Define your language…. From there, you can create new user language and set stylers for keywords, operators, and other language facets. Stylers can set font color, size, and style. Users can also import and export UDLs as XML files for sharing. Since the highlighting doesn’t rely upon a context-free grammar, it has its limits. For example, keywords may still be highlighted when not actually being used as keywords in the language. Nevertheless, it’s better than nothing.

Since I do a lot of behavior-driven test automation development, I created a UDL for Gherkin. You can download it from the Automation Panda Github repository – the file is named gherkin_npp_udl.xml. Import it into Notepad++, and you’re ready to go!

Below is a screen shot of an example feature file:

npp_gherkin

An example feature file using my Notepad++ UDL for Gherkin

13 comments

  1. Time spent with Andy will save us from reading and extracting information from 10 reference books. I will be downloading this plugin and shall post my experience in this post.

    Like

  2. I downloaded
    – a fresh copy of Notepad++
    – gherkin_npp_udl.xml

    I tried to import the xml into Notepad++ (Language > Define you language… > Import…)

    Got the error: Failed to import

    Am I doing something wrong?

    Thanks for the post!

    –Daniel

    Like

    1. Those should be the correct steps. I’ll try to troubleshoot in the next day or two. Maybe there’s a file format problem (unix2dos) or a change in the latest version of Notepad++.

      Like

    2. This could happen if you just download the file. Copy it from the ‘raw’ view instead and create a new file to import.

      //Ulf

      Like

  3. Would love to figure out how to highlight numbers.
    For example:
    1
    20
    2018
    12345678901234567890
    2018-07-05
    2018/07/05

    Just the numbers would need to be highlighted.

    I’ve tried a number of scenarios but can’t get it to work.

    Like

    1. You *could* play around with the Notepad++ UDL to make it highlight numbers, but I question if you *should*. In Gherkin, numbers are treated just like any other plain text for a step. There is nothing special about them. If you want numbers to be used as step arguments, then I recommend the best practice of surrounding arguments with double-quotes. For example: Given I have a basket with “3” cucumbers. The UDL I provided will highlight any arguments surrounded by double-quotes.

      Like

  4. I’m a little late to the party, here. But has anyone been able to accomplish code folding on the scenarios? I just can’t seem to figure that one.

    Like

  5. Good post (as always, Yesterday I discovered this blog, it is amazing! I’ve been reading all posts of the BDD-101 series!!)

    Just to add, if you’re a Linux user, you can also install Notepadqq, it already has syntax highlighting for Gherkin. Just open a Gherkin file and then go to Languages -> G -> Gherkin.

    Easy as that!

    Or, if you want to use Notepadqq mainly for working with Gherkin files. In Notepadqq go to Settings -> Preferences -> Languages and select Gherkin as your default Language.))

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s