In the past I have used a variety of different editors, but over the last four or five years, I have stuck with Sublime Text. There are various reasons for this: it’s fast, reliable, extendable and feature rich.
I’m hoping over the course of this post, you will learn something new or think of ways to improve productivity whilst using it.
The following shortcuts will help eliminate the use of the mouse and get to where you want faster. I wasn’t convinced to begin with, but now I’m sold and I love it.
This shortcut is extremely useful and quick way opening files, especially on big projects with lots of nested directories.
The above three methods as described will just affect the current page you are on, you can enter the filename before the operator to perform the action on other files. This can be extremely useful if you have an error on a page.
Here are some other shortcuts that I use regularly:
Shortcut | Function |
Crtl + r | Find/Jump to a function on the current file |
Crtl + h | Opens the search/replace box |
Ctrl + o | Open a file with the file explorer |
Ctrl + g | Goto a line number on the current file |
Ctrl + l | Selects the current line |
Ctrl + n | Opens a new file |
Ctrl + / | Comments out the current line when the cursor is at any point on the line |
Ctrl + -/+ | Decreases and increases text size on the current file |
Ctrl + [ / ] | Increase and decreases the current lines indentation when the cursor is at any point on the line |
Crtl + Shift + k | Delete current line |
I always try to refactor code to keep improving it, and sometimes that includes renaming variables so they make more sense. One way to do it would be find and replace, another way is highlight a variable, then press Ctrl + d, this will then highlight the next occurrence of that variable, keep pressing Ctrl + d until all the variables are selected and change as required:
Another feature of sublime is multiple cursors. They are extremely useful when performing repetitive actions. For example making a quick array.
To do this select all the lines
Press Ctrl + Shift + l
So once you have your line of code, highlight it all and then press the [ key, and that will put square brackets around it.
You can also create multiple cursors by holding the ctrl key down and clicking where you want the additional cursors.
I don’t use this too much, but when looking at new code, I use the code folding to make it easier to look at all the methods, especially if there is a lot of code. Then you can unfold individual methods that you are interested in.
Above are just a few of the shortcuts, there are a lot more out there. To see them all go to “Preferences > Key Bindings”. As I mentioned above, a reason I like Sublime is because you can customise the editor, so on the Key Bindings section you can overwrite the bindings by pasting the relevant overwrite on the right hand pane.
Just like Key Bindings you can customise the settings, so go to “Preferences > Settings”. On the left hand pane you can see all the default settings. It’s worth having a look and seeing which to customise. Below are a few I do:
My first framework was Zend framework which had its own style guide, and is also covered in PSR-2 standard. I try to keep the line length to respectable length. To make this easier you can set rulers. To do this add
"rulers": [ 80, 120 ]
"show_encoding": true, "show_line_endings": true, "tab_size": 4, "translate_tabs_to_spaces": true, "trim_trailing_white_space_on_save": true, "word_wrap": "true"
I’ve seen people customise the theme, the fonts, sizes etc, but to be honest I’m happy with what comes as default, especially the new theme recently added.
One of the biggest features of sublime is its packages. I always install plugins using the “Package Control” plugin.
To install this visit the following site and follow the instructions
Then to install the package:
Some of the packages I use are:
Another one from PSR-2 standards “There MUST NOT be trailing whitespace at the end of non-blank lines.” This package is really good for seeing and removing trailing spaces.
For php doc blocks i use DocBlockr. There is an option section in the documentation where you can customise the package even more.
I’ve seen some people remove the sidebar and just use shortcuts, but I still find it useful. The context menu on the side bar out of the box on sublime is not the best, but this package enhances it a lot.
One massive time saving part of sublime is snippets. I’ve got various set up. Lets walk through a quick example.
So let’s just create a really simple multiplier method for php.
private function multiplier(int $multiplier, float $value): float { return $multiplier * $value; }
to manually type this out would take some time, sublime already had some autocomplete features installed but you can do more to automate this. Create a new snippet:
Tools > Developer > New Snippet
and paste the following code in:
<snippet> <content><![CDATA[ ${1:private} function $2($3): ${4:string} { $5 } ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>cm</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.php</scope> </snippet>
Then save this is in the following location (this is part of the path as it can differ from machine to machine) \Sublime Text 3\Packages\User
Using the extension .sublime-snippet, so i’ve just called mine method.sublime-snippet.
So now in your project type cm and then press tab and you will get the following:
private function (): string { }
private should be highlighted, so you can change to public if required, then just keep tabbing to the next section, adding or changing as required.
Above is a coding php example but it can be used for any other language, especially front end development. If you use a particular templating framework then what about using a snippet for form fields or columns? Anything basically that you type/copy regularly.
You can split sublime screen into a grid view, columns or rows by looking at “View > Layout” however I don’t tend to use this feature, although could be very useful when templating.
If you like Vi then switch this mode on (more information here)
This is a quick overview of how I have my editor setup. I’m sure I’m probably just using a fraction of what Sublime is capable of though. If you have an time saving methods or packages then why don’t you comment below?
Like what you’ve read, then why not tell others about it... they might enjoy it too
If you think Bronco has the skills to take your business forward then what are you waiting for?
Get in Touch Today!
Discussion