Last week, JetBrains released RubyMine 6.0. The most significant feature is multi-project support; perfect for component-based Rails architectures. However, in this post, we’ll look at OS X keyboard shortcuts for some of the other new features.buy ultram onlinebuy diazepam online without prescriptionvalium online no prescription buy tramadol without prescription soma online no prescription provigil online pharmacy adipex online without prescription ativan online no prescription buy ambien without prescription buy klonopin online buy xanax online
By selectively hiding and showing sections of code, code folding allows you to focus on what’s relevant, while ignoring irrelevant details. Code folding is also a useful way for quickly getting a high-level overview of a large section of code. RubyMine adds custom folds to the standard list of editor code folding features. Custom folds can be used to effectively outline a section of code. In this post, we’ll look at code folding in RubyMine on OS X.
Folding Individual Code Blocks
A code folding toggle icon appears in the left gutter next to blocks of code that can be folded. Press
command + - and
command + + to fold and unfold foldable blocks.
Folding All Code Blocks
Fold and unfold an entire file’s code blocks with
command + shift + - and
command + shift + +.
After folding all the code blocks in a file, successively unfolding with
command + + will unfold to your cursor.
If a section of code does not have a folding toggle icon in the gutter, select it, then fold it with
command + ..
A folded selection appears as an ellipsis. Unfold it with
command + . or
command + +.
Custom Folding Regions
A custom folding region can be used to describe or outline a section of code. RubyMine uses a special Ruby comment for custom folding regions.
To create a custom folding region, first select the section of code, then press
command + option + T and choose “<editor-fold…> Comments” or “region…endregion Comments” from the “Surround With” dialog.
Finally, provide a description for the custom folding region.
You’ll have to manually create this comment if RubyMine doesn’t give you either comment option in the “Surround With” dialog.
Navigating By Custom Folding Regions
Navigate to a custom folding region with
command + option + ..
RubyMine can be configured to automatically fold certain code constructs, e.g., methods. To set these preferences, search for “code folding” in the settings dialog,
command + ,.
Don’t Forget About the Details
Not every developer is a fan of code folding. Folds are often used to hide long, ugly, or complicated sections of code. Once hidden, the code rots; out of sight, out of mind. On the other hand, hiding code behind folds keeps you focused, preventing unnecessary refactoring tangents. Like any technique, code folding has its pros and cons, try it out and see if it works for you.
RubyMine’s powerful “Go to file” command allows you to quickly jump to a particular file in a project. This is a great way to get started, but a development session often ends up being confined to a small set of files and directories. It’s inefficient to constantly search project-wide. Instead, use RubyMine’s convenient inline navigation bar to find nearby files. In this post, we’ll take a look at it on OS X.
Navigation Bar Basics
Open the navigation bar with
command + Up.
Navigate the navigation bar with the arrow keys or
control + N and
control + P. If you know the name of the file or directory you’re looking for, start typing it to find it via search.
This search bar supports many of the same fuzzy search features available in “Go to file”,
command + shift + O.
The navigation bar can also be permanently docked. Use “Find Action”,
command + shift + A, then search for “Navigation Bar”.
File management commands available in the Project tool window also work in the navigation bar.
command + N– create a new file or directory
F5– copy a file or directory
shift + F5– clone a file or directory
F6– move a file or directory
shift + F6– rename a file or directory
delete– delete a file or directory
Performing these commands from the inline navigation bar minimizes context switching. It also avoids wasting screen space on the Project tool window.
Preview files from the navigation bar with “Quick Definition”,
option + spacebar.
Development of a particular feature or bug fix is often localized to a set of code and test files. An effective strategy is to find a known initial file with “Go to file”,
command + shift + O, then work with and manage nearby related files and directories with the navigation bar. The navigation bar becomes a sort of local “Go to file” command.
RubyMine includes several commands to quickly perform common tasks, such as converting a Hash from Ruby 1.8 to 1.9 syntax, or viewing an object’s documentation without leaving the current file. These powerful commands eliminate tedious editing and context switching. In this post, we’ll explore them on OS X.
A lightbulb icon indicates intentions are available for the current line. View them with
alt/option + enter.
Quick Documentation Lookup
View documentation inline with
shift + F1 to view it in an external web browser.
If the docs are no help, press
alt/option + space to view the definition inline.
This is a useful way to check if something is defined.
Quick Evaluate Expression
During a debugging session, inspect an object inline with
command + alt/option + F8.
Quick Switch Scheme
Switch the color scheme, code style scheme, keymap, or look and feel with
control + `
Simple But Powerful
RubyMine’s “quick” commands showcase the power of an IDE. Intentions/quick fixes was the feature that convinced me to dive deeper into RubyMine. Viewing information inline saves time, and avoids losing focus. Once integrated into your workflow, “quick” commands will become some of your most used commands.
After opening a file, your next step is usually to search within that file for some text, or perhaps, a particular method. Like text editors, RubyMine supports simple text search. However, it also offers more powerful method and usage search. In this post, we’ll look at various ways to search within a file in RubyMine on OS X.
command + F to search for text within the current file. Use
command + G and
command + shift + G to move forward and backward through the search results.
After selecting text, search for it with
command + F.
After beginning a text search with
command + F, press
control + H to view recent searches.
Repeat the last text search by not entering a query into the search bar, and then pressing
Enable quick word searching by adding a shortcut for the “Find Word at Caret” command. I map it to
control + F3. If you use this mapping, then you may have to disable the OS X “Move focus to the the dock” shortcut.
command + F12 to view the structure of the current file in a popup, then type the name of the method you’re looking for.
This is quicker and more accurate than using text search.
Find usages in the current file of the symbol under caret (e.g., a variable, method, or class) with
command + F7. Use
command + G and
command + shift + G to move forward and backward through the usages.
Highlight usages in the current file of the symbol under caret with
command + shift + F7. Use
command + G and
command + shift + G to move forward and backward through the usages.
Esc to clear the highlighting.
Search for Code Not Text
By being aware of code, an IDE can allow you to search for a method, instead of performing a text search such as “def show”. Text search will always have its time and place, but use it as a last resort. Move on from old text editor habits and learn your IDE’s more powerful alternatives.
During development, it’s common to view and edit the same group of related files, to navigate the same classes, and to run and rerun the same tests. An IDE that keeps track of recent activities can help simplify performing these types of repetitive development tasks. In this post, we’ll look at how to view and re-execute recent activities in RubyMine on OS X.
Refactoring is the process of changing the internal structure of code without changing its external behavior. Successful refactorings involve taking very small, sometimes tedious, steps. Fortunately, many refactorings are simple enough to be automated. In this post, we’ll look at automated refactorings in RubyMine on OS X.
When the name of a variable, method, or class doesn’t explain its purpose, rename it with
shift + F6.
Help explain complex expressions by introducing variables with
command + option + V.
Move related logic into a separate method with
command + option + M.
Inline Variable or Method
Inline variables and methods that don’t increase clarity with
command + option + N
Less frequently used refactorings, such as extracting a superclass or module, are available from the “Refactor This…” dialog,
control + T.
Automation Makes a Difference
Refactoring is a significant part of everyday development. It’s the final step in TDD’s mantra of red, green, refactor. We often refactor inherited code to help us better understand it. Automating refactoring encourages more refactoring. If a simple class rename involves
sed, then it’s time to upgrade to an IDE.
As a long-time command-line Git user, I was hesitant to adopt RubyMine’s version control tools. But I decided to give them a try, and I’m glad I did. RubyMine’s version control tools make common Git commands more accessible and easier to execute. The addition of a GUI is great for tasks such as diffing a file, or viewing commit logs. In this post, we’ll look at performing everyday Git commands in RubyMine on OS X.
You can view a diff of all your changes from the Changes tool window.
command + 9 to open the Changes tool window. Then press
command + D to view a diff of all your changes.
You can diff a single file by selecting “Compare with the Same Repository Version” from the VCS Operations popup. Press
control + V to open the VCS Operations popup.
command + K to commit changes.
Select “Push…” from the VCS Operations popup,
control + V, to push your local changes.
command + T to pull in the latest changes.
To view the Git log, open the Changes tool window,
command + 9, then navigate to the Log tab with
command + shift + ].
To see the log of a single file, select “Show History” from the VCS Operations popup,
control + V.
This will open the log in the Version Control tool window.
Revert changes by selecting “Revert” from the VCS Operations popup,
control + V.
Determine who changed a file by selecting “Annotate” from the VCS Operations popup,
control + V.
The committers will be displayed to the left of the editor gutter.
Don’t Abandon the Command-line
In this post, I focused on the most commonly used Git commands. RubyMine also includes support for more powerful Git commands, such as
git-rebase. However, I find their RubyMine GUI-based implementations slow and clumsy. As much as I want to stay in RubyMine, I find the best version control strategy is to use RubyMine for common Git commands, but turn to the command-line for the hard stuff.
RubyMine’s editor is tab-based. When you open a file, it’s opened in a new tab. The editor can also be split vertically or horizontally; allowing you to edit multiple files simultaneously. In this post, we’ll look at managing and navigating these basic RubyMine concepts on OS X.
Navigating Between Tabs
Move between multiple tabs with
command + shift + [/] or
control + Left/Right.
Close a tab with
command + W.
There are several other useful tab closing commands that don’t have keyboard shortcuts. I add the following shortcuts for them:
command + shift + W– close all other tabs
command + option + W– close all tabs
command + option + control + W– close all unmodified tabs
Splitting the Editor
Edit multiple files simultaneously by splitting the editor using the “Split Vertically” or “Split Horizontally” commands (find these commands quickly with
command + shift + A, “Find Action”).
command + option + control + Up/Down shortcuts to split vertically and horizontally.
Navigating Between Splits
Move the cursor to the next split with
option + Tab. Move to the previous split with
option + shift + Tab.
The Switcher can also be used to move between splits. Use
control + Tab to open the Switcher, continue holding down
control, and then use
Tab to select an open file to navigate to.
Moving Tabs Between Splits
Use the “Move To Opposite Group” command (find this command quickly with
command + shift + A, “Find Action”) to move tabs between splits.
command + option + control + Left/Right shortcuts for this command.
Close a single split by closing all of its tabs.
Close all splits with
option + shift + X.
Master the Basics
In RubyMine, you’ll use tabs and splits all the time. Don’t hesitate to create custom shortcuts for tab and split commands that don’t have them. Efficiently managing and navigating tabs and splits from the keyboard is a fundamental, must learn RubyMine skill.
When learning how to program, you were probably taught not to copy and paste code. Typing it out manually improved your understanding of its syntax and structure. However, after learning a particular concept, repeatedly typing it becomes boring and tedious. An IDE can help you automate this process by intelligently generating boilerplate code. In this post, we’ll take a look at code generation in RubyMine on OS X.
Generating Getters and Setters
If a class has instance variables, press
command + N in the editor to generate getters, setters, or both.
After selecting what type of method to generate, RubyMine will prompt you for the instance variable to generate it for.
Generating Overridden Methods
control + O to view a list of overridable methods.
Select a method from this dialog to generate a stub for it.
Generating Surrounding Code
Surround code with conditionals and other language constructs using
command + alt/option + T.
Remove surrounding code with
command + shift + delete.
RubyMine’s intentions offer many different ways for generating and modifying code. A yellow lightbulb icon in the editor indicates that intentions are available.
alt/option + enter to view the intention. Press
enter to execute it.
Intentions can even create classes.
Use intentions to modify code e.g., converting from Ruby 1.8 to 1.9 Hash syntax or converting a string from double to single quotes.
RubyMine’s live templates are commonly known as snippets in other editors. Press
command + J to view the list of available live templates.
Live templates are more commonly inserted by typing an abbreviation and then pressing
Here’s some of my favorite live templates:
def– create an instance method
defs– create a class (singleton) method
do– create a
doo– create a
do |object| ...endblock that expects an argument
it– create an RSpec example
p– access a Rails controller’s
s– access a Rails controller’s
Once you understand a particular concept, Ruby or Rails, as a programmer, your goal should be to automate it. If you’re beginning Ruby or Rails, then I would avoid code generation in order to better familiarize yourself with the language and framework. However, if you’re a veteran Rubyist, then I see nothing wrong with automating what you already know.
RubyMine’s tool windows integrate common development tasks such as searching, debugging, and version control, into the IDE. This eliminates context switching to external tools, providing a more fluid development experience. In this post, we’ll look at some common commands for managing tool windows in RubyMine on OS X.
Opening and Closing Tool Windows
Each tool window is given a number. They can be opened or closed with
command + <number>, e.g., by default, the Project tool window is given
command + 1.
Opened tool windows are located on the bottom and sides of the IDE.
Navigating Between Tool Windows
To navigate between opened tool windows, first open the Switcher with
control + tab. Then continue holding down
control and press the number of a specific tool window.
While holding down
option to move between the Switcher’s two columns.
Navigating Between Tool Windows and the Editor
esc in a tool window to move focus to the editor. Use
F12 to move focus back to the tool window.
Closing Tool Windows
Close tool windows with
command + w. Use
shift + esc in a tool window to close it and move focus to the editor.
Close all opened tool windows and move focus to the editor with
command + shift + F12. Press it again to re-open the tool windows.
Don’t Sell Your IDE Short
Many developers insist of performing certain tasks outside their IDE. Perhaps they fear losing skills they’ve heavily invested in. For certain exceptional situations, e.g., debugging production, it’s important to know how to do these tasks without an IDE. But when it comes to day-to-day development, embrace your IDE and experiment with a new way of doing old things.
Before using RubyMine, my debugging workflow went something like this:
Why isn’t this test passing?. It should’ve passed. Let me add a few
Kernel#putscalls to see what’s going on. Hmmm, ok, it’s still failing. I’m going to need some more output. Man, these tests take forever to run. Syntax error?!. Ugh, typo…
Debugging like this isn’t fun; especially when pairing. Fortunately, RubyMine can help. RubyMine includes a standard debugger that has minimal setup and works out of the box. I still don’t enjoy debugging, but RubyMine has made it much less painful. In this post, we’ll look at debugging in RubyMine on OS X.
Add or remove breakpoints with
command + F8.
View existing breakpoints with
command + shift + F8.
Starting the Debugger
Debug the current program with
control + shift + D. This will automatically open the Debug tool window (
command + 5).
control + D to re-run the last debug session. View recent debug sessions with
control + alt/option + D.
Examining a Program
Examine variables in the Debug tool window’s variables pane.
command + N in the Debug tool window’s Watches pane to watch a specific variable.
backspace will delete a watch.
alt/option + F8 to evaluate arbitrary expressions.
control + space triggers autocompletion.
Instead of using the Debug tool window, examine a variable inline by placing your cursor on it and pressing
command + alt/option + F8.
Stepping through a Program
Step into a method with
F7. Step over a method with
F8. Step out of a method with
shift + F8.
Use your cursor as a temporary breakpoint with
alt/option + F9. Continue your debug session with
If you’re using an IDE, take time to learn its debugger. Don’t litter your code with
Kernel#puts and friends. Instead, set a breakpoint, start the debugger, examine some objects, and slowly step through your problems.