This is the start of a series of posts to help you better utilize your most important tool in developing, your text editor. For this course we are recommending that you start out with Sublime Text 2. If you have chosen a different editor, read the shortcuts below and find the equivalent actions in your chosen editor. As usual, ask your mentor if you have questions or would like these demonstrated.
The goal of learning these shortcuts is to keep your hands on the keyboard as much as possible and to keep your hands in the same position on the keyboard. Using your mouse moves your hands from the keyboard and can slow your coding.
Autocomplete
Sublime by default gives you many autocomplete features. As you start typing a word you may get a context menu of possible choices. Pressing tab
selects the choice that is currently highlighted. Continue to type out the word until it becomes the highlighted choice or use the arrow keys to highlight the correct choice, then press tab to finish the word. This feature becomes more useful as your program gets bigger, as this context list will expand as you create methods and assign variables.
Comment/Uncomment Lines
No matter where the cursor is on the line, this shortcut will comment the whole line or uncomment if the line has already been made a comment. (In Ruby lines starting with #
are comment lines, or lines that are not executed) The file's syntax must be set to Ruby in order for these key shortcuts to work. This is most easily done by saving the file with a .rb
extension.
Comment/Uncomment:
Mac: cmd + /
Win: ctrl + /
Add line below current line
Instead of moving your cursor to the end of the line and pressing enter
, use:
Mac: cmd + return
Win: ctrl + return
Add line above current line
Instead of moving your cursor to the beginning of the line and pressing enter
and then moving the cursor up with the up arrow
, use:
Mac: cmd + shift + return
Win: ctrl + shift + return
Delete current line
Instead of highlighting the whole line with the mouse and then pressing delete, use:
Mac: cmd + x
Win: ctrl + x
Move Cursor functions
Unfortunately, Sublime doesn't have the greatest key commands for moving your cursor around without the mouse. By default the arrow keys are used for moving your cursor around. You can command the cmd
key or ctrl
key to skip to the beginning or end of the line:
Mac:
Go to end of line: cmd + right arrow
Go to beg. of line: cmd + left arrow
Win:
Go to end of line: ctrl + right arrow
Go to beg. of line: ctrl + left arrow
Next post, I will discuss some of the basic setting's you should begin with and show you how to customize key shortcuts that can make Sublime more useful.