Installing and Working with the Sublime Text Editor Along with Tips and Tricks
This guide walks through how to install and then work with the Sublime Text editor. This includes how to work with common tasks in Sublime such as: searching, making multiple changes at the same time, and performing the fuzzy file search.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this guide, we're going to be installing our text editor.

Ruby and the entire Rails ecosystem is much different than other programming languages like .NET, C# and Java. Those languages require something called an Integrated Development Environment (IDE) that have built-in debuggers and you can run the code inside that system itself.

There are also some IDEs for Ruby such as RubyMine. Developed by JetBrains, it is a fantastic IDE that allows you to run your tests and code within the system. You could follow along the course using that if you choose. Personally, I don't use it because it's heavy, and I prefer something that's lightweight. But, I know a lot of developers who use it, so feel free to try it if you want.

What I use in my courses is something called Sublime Text 3. In my day to day development I use Vim. Vim is an IDE built directly into the terminal. It is complex, and would need its own course to learn.

Installing Sublime

If you're learning Ruby for the first time, I'd suggest focusing on the code first and recommend Sublime. You can go to sublimetext.com/3 and download it for free.

Once the download is complete, right-click on it and choose Open. Install it, and you should be ready to move forward.

One of he nice options in Sublime is that when you open a directory by choosing File < Open or CTRL+O, it will let you browse for the file you want. Once you click the open button, sublime will open the entire file system for that project, on the left hand side of your screen.
just like this:

large

Now, you can click on any file to view it.

Sublime has hundreds of shortcuts. Though we can't go through everything, I'll talk about some shortcuts that'll speed up your programming process.

Fuzzy Search

The first one is fuzzy search, and the shortcut is COMMAND +T. This opens up a fuzzy search pane. You can search for a file with any text from the file name. Just start typing letters from the file you want and you will see a list of any files with corresponding letters.

large

This is an incredibly helpful feature and can save a lot of time for you because you can find even the most deeply nested file within seconds. This could be a real time-saver, especially when you want to find a file in a large application containing hundreds of files.

Screen Splitting

Another cool thing that you'll see me do a lot in this course is screen splitting. If I want to see two files at the same time, I can split the screen, so the top half displays one file, and the bottom half the other.

To do that, go to View > Layout, and here you'll see many options. You can choose the format that best meets your preferences: Columns, Rows, or a Grid. You can drag the tab of the file you want to the section you wish. You can also adjust the section or row sizes by dragging on the bar or line delineating the break.

Now, I can look at two files like this:

large

The grid layout allows you to see four files at the same time.

I'd definitely recommend you play around with this a little bit, as it can come quite handy during development.

Universal Search

The next thing we're going to cover is universal search. Let's say, you have a method but you have no idea what file it is in. To search for that, press COMMAND+SHIFT+F, and this will bring up a search box at the bottom with a full set of universal search items. Enter your method name into the Find box and click on Find button, the search will bring up all the files that have that method. Double click on the hightlighted portion of the search results and it will open the file itself. This can come in very handy.

large

To search within a single file, type COMMAND+F. If you enter a specific word, the file will highlight all the instances of that word. If you hit return it will take you through each of those instances. Alternately, if you hit the Find All button, then it will not only hightlight all the instances, it will also select them all. The obvious advantage is you can make a single change, and all the instances will be changed as well.

You also have the ability to fix multiple instances at the same time without the search function. Simply hold the COMMAND button and click on all the areas that need to be changed, and then start typing your code. This would be a great way to add a class to multiple header tags all at once.

Fixing Indentation

Sublime has a default of four spaces for indentation. The default also does not convert your tabs into spaces. This would result in some fairly messy indenting issues if you wanted to share your code with another developer. Ruby is very specific about indentation. While it won't change the way that the code is interpreted, Ruby developers are used to seeing specific indentation styles. This is why we need to change some preferences right at the beginning.

Go to the tab labelled Sublime Text > Preferences > Settings

This will bring up a window with all the default settings.

large

There are a whole lot of things you can change here like your line numbers and gutters. The most important attribute is tab_size, and this should be changed from 4 to 2. Also, set translate_Tabs_to_spaces to true. You can make these changes on the right window, which is the preferences for users.

Resources