Using Notepad++ for Writing Ruby Programs in Windows

If you are writing small Ruby programs and you don’t need facilities such as debugging available in a full fledged IDE, I recommend using Notepad++ editor. Notepad++ has built in syntax highlighting for Ruby and is a light weight and fully featured code editor.

Download the latest version of Notepad++ from here. I recommend download the Windows installer version. The download size is about 5MB. Double click on the downloaded executable to install Notepad++.

Installing Notepad++ in Windows 7

Choose the folder where you want Notepad++ to be installed and click on Next.

Notepad++ installation options

Customize your installation and choose what you need. I recommend enabling plugins, themes and auto updater. Click on Next.

Notepad++ installation options

Click on "Don’t use %APPDATA%" option. When you select this option, all the customization you do in your Notepad++ installation will be stored in the installation folder itself. This way you can copy the installed folder to another machine if you need to change your machine.  Click on Install to complete Notepad++ installation.

Run Notepad++ editor by clicking on the desktop icon. Let us first configure Notepad++ for editing Ruby programs.

From the Notepad++ menu, click on Settings => Preferences. Click on Language Menu/Tab settings. Under the tab settings for [Default] modify the tab size and Replace by space options as shown below. We set the tab size to 2 and we set Replace by space option to use spaces instead of tab character.

Setting editor properties in Notepad++ for Ruby

Now we will add a custom menu in the Run menu for running Ruby programs. This way you can run Ruby programs directly from the Notepad++ editor. From the Notepad++ menu, click on Run => Run. This opens up the following window.

Configuring a shortcut for running Ruby programs in Notepad++

In the text field, enter the following command. In order for this to work, you need to have Ruby 1.9.x installed and the Ruby bin folder must be on the PATH environment variable. See this tutorial for step by step instructions on installing Ruby in Windows.

cmd /K ruby "$(FULL_CURRENT_PATH)"

Click on the Save… button to save this as a custom command.

Configuring a shortcut for running Ruby programs in Notepad++

Enter a name for the shortcut (Run Ruby Program) and then select a keyboard shortcut for running the command (F6). Click on OK.

Now from the Notepad++ menu, Click on Run. You will see the additional "Run Ruby Program" menu as shown below.

Custom Run Ruby option in Notepad++

In order for this shortcut to work, you need to ensure that your Ruby program is saved in a file. To test Notepad++, type in the following program,

def fact(n)
  if n==1
    n * fact(n-1)
puts fact(5)

Save the file as factorial.rb. Now press F6 key or select the "Run Ruby Program" submenu from the Run menu. You should see the output of the Ruby program in a command window as shown below,

Ruby program output from Notepad++

Leave a Reply