{"id":4556,"date":"2017-10-12T12:22:02","date_gmt":"2017-10-12T11:22:02","guid":{"rendered":"https:\/\/www.bronco.co.uk\/our-ideas\/?p=4556"},"modified":"2017-10-12T14:11:17","modified_gmt":"2017-10-12T13:11:17","slug":"sublime-text-3-tips-and-tricks-to-improve-productivity","status":"publish","type":"post","link":"https:\/\/www.bronco.co.uk\/our-ideas\/sublime-text-3-tips-and-tricks-to-improve-productivity\/","title":{"rendered":"Sublime Text 3: Tips and Tricks to Improve Productivity"},"content":{"rendered":"<p>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&#8217;s fast, reliable, extendable and feature rich.<br \/>\nI\u2019m hoping over the course of this post, you will learn something new or think of ways to improve productivity whilst using\u00a0it.<\/p>\n<h2>Sublime Shortcuts<\/h2>\n<p>The following shortcuts will help eliminate the use of the mouse and get to where you want faster.\u00a0 I wasn\u2019t convinced to begin with, but now I\u2019m sold and I love it.<\/p>\n<h4>Opening Files Quickly<\/h4>\n<p>This shortcut is extremely useful and quick way opening files, especially on big projects with lots of nested directories.<\/p>\n<ol>\n<li>Firstly, Press Ctrl + p<\/li>\n<li>Now type in the filename or file path and filename<\/li>\n<li>A list of files will appear, use the up\/down arrow keys and then press enter to open it<\/li>\n<\/ol>\n<h4>Find\/Jump to a Function<\/h4>\n<ol>\n<li>Press Ctrl + p, then @<\/li>\n<li>A list of functions will appear, start typing the function name or use the up\/down arrows to highlight the correct function and click enter to jump to it.<\/li>\n<\/ol>\n<h4>Search Within the File<\/h4>\n<ol>\n<li>Press Ctrl + p, then #<\/li>\n<li>A list of words will appear, type the word you want to find and they will highlight<\/li>\n<\/ol>\n<h4>Go To A Line Number<\/h4>\n<ol>\n<li>Press Ctrl + p, then :<\/li>\n<li>Then type in the line number. Press enter.<\/li>\n<\/ol>\n<p>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.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4565\" src=\"https:\/\/www.bronco.co.uk\/our-ideas\/wp-content\/uploads\/2017\/10\/finding-error-line-number.gif\" alt=\"finding-error-line-number\" width=\"1243\" height=\"602\" \/><\/p>\n<h4>Other Shortcuts<\/h4>\n<p>Here are some other shortcuts that I use regularly:<\/p>\n<table border=\"1px\" cellspacing=\"10px\">\n<tbody>\n<tr>\n<td>Shortcut<\/td>\n<td>Function<\/td>\n<\/tr>\n<tr>\n<td>Crtl + r<\/td>\n<td>Find\/Jump to a function on the current file<\/td>\n<\/tr>\n<tr>\n<td>Crtl + h<\/td>\n<td>Opens the search\/replace box<\/td>\n<\/tr>\n<tr>\n<td>Ctrl + o<\/td>\n<td>Open a file with the file explorer<\/td>\n<\/tr>\n<tr>\n<td>Ctrl + g<\/td>\n<td>Goto a line number on \u00a0the current file<\/td>\n<\/tr>\n<tr>\n<td>Ctrl + l<\/td>\n<td>Selects the current line<\/td>\n<\/tr>\n<tr>\n<td>Ctrl + n<\/td>\n<td>Opens a new file<\/td>\n<\/tr>\n<tr>\n<td>Ctrl + \/<\/td>\n<td>Comments out the current line when the cursor is at any point on the line<\/td>\n<\/tr>\n<tr>\n<td>Ctrl + -\/+<\/td>\n<td>Decreases and increases text size on the current file<\/td>\n<\/tr>\n<tr>\n<td>Ctrl + [ \/ ]<\/td>\n<td>Increase and decreases the current lines indentation when the cursor is at any point on the line<\/td>\n<\/tr>\n<tr>\n<td>Crtl + Shift + k<\/td>\n<td>Delete current line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Refactoring<\/h4>\n<p>I always try to refactor code to keep improving it, and sometimes that includes renaming variables so they make more sense.\u00a0 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:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4572\" src=\"https:\/\/www.bronco.co.uk\/our-ideas\/wp-content\/uploads\/2017\/10\/control-and-d.gif\" alt=\"Refactoring\" width=\"1237\" height=\"590\" \/><\/p>\n<h4>Multiple Cursors<\/h4>\n<p>Another feature of sublime is multiple cursors. They are extremely useful when performing repetitive actions. For example making a quick array.<\/p>\n<p>To do this select all the lines<\/p>\n<p>Press Ctrl + Shift + l<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4573\" src=\"https:\/\/www.bronco.co.uk\/our-ideas\/wp-content\/uploads\/2017\/10\/making-an-array-from-list.gif\" alt=\"Making an Array from a List\" width=\"1237\" height=\"590\" \/><\/p>\n<p>So once you have your line of code, highlight it all and then press the [ key, and that will put square brackets around it.<\/p>\n<p>You can also create multiple cursors by holding the ctrl key down and clicking where you want the additional cursors.<\/p>\n<h4>Code Folding<\/h4>\n<p>I don\u2019t 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.\u00a0 Then you can unfold individual methods that you are interested in.<\/p>\n<h4>Full List of Shortcuts<\/h4>\n<p>Above are\u00a0 just a few of the shortcuts, there are a lot more out there.\u00a0 To see them all go to &#8220;Preferences &gt; Key Bindings&#8221;.\u00a0 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.<\/p>\n<h2>Settings<\/h2>\n<p>Just like Key Bindings you can customise the settings, so go to &#8220;Preferences &gt; Settings&#8221;.\u00a0 On the left hand pane you can see all the default settings.\u00a0 It&#8217;s worth having a look and seeing which to customise.\u00a0 Below are a few I do:<\/p>\n<h4>Line Length<\/h4>\n<p>My first framework was <a href=\"https:\/\/framework.zend.com\/manual\/2.4\/en\/ref\/coding.standard.html#maximum-line-length\">Zend framework<\/a> which had its own style guide, and is also covered in <a href=\"http:\/\/www.php-fig.org\/psr\/psr-2\/#23-lines\">PSR-2 standard<\/a>. I try to keep the line length to respectable length. To make this easier you can set rulers. To do this add<\/p>\n<pre class=\"lang:default decode:true\">\"rulers\":\r\n[\r\n    80,\r\n    120\r\n]\r\n<\/pre>\n<h4>Others<\/h4>\n<pre class=\"lang:default decode:true\">\"show_encoding\": true,\r\n\"show_line_endings\": true,\r\n\"tab_size\": 4,\r\n\"translate_tabs_to_spaces\": true,\r\n\"trim_trailing_white_space_on_save\": true,\r\n\"word_wrap\": \"true\"\r\n\r\n<\/pre>\n<p>I&#8217;ve seen people customise the theme, the fonts, sizes etc, but to be honest I&#8217;m happy with what comes as default, especially the new theme recently added.<\/p>\n<h2>Packages<\/h2>\n<p>One of the biggest features of sublime is its packages. I always install plugins using the &#8220;Package Control&#8221; plugin.<\/p>\n<p>To install this visit the following site and <a href=\"https:\/\/packagecontrol.io\/installation\">follow the instructions<\/a><\/p>\n<p>Then to install the package:<\/p>\n<ol>\n<li>Press Ctrl + Shift+ p<\/li>\n<li>Type install<\/li>\n<li>Then click on<\/li>\n<li>Package Control: Install Package<\/li>\n<li>A list of packages will appear, again use the autocomplete to search for the plugin, click the correct one from the dropdown and it will install automatically.<\/li>\n<\/ol>\n<p>Some of the packages I use are:<\/p>\n<h4>Trailing Spaces<\/h4>\n<p>Another one from PSR-2 standards &#8220;There MUST NOT be trailing whitespace at the end of non-blank lines.&#8221; <a href=\"https:\/\/packagecontrol.io\/packages\/TrailingSpaces\">This package<\/a> is really good for seeing and removing trailing spaces.<\/p>\n<h4>DocBlocks<\/h4>\n<p>For php doc blocks i use <a href=\"https:\/\/packagecontrol.io\/packages\/DocBlockr\">DocBlockr<\/a>. There is an option section in the documentation where you can customise the package even more.<\/p>\n<h4>Sidebar Enhancements<\/h4>\n<p>I\u2019ve seen some people remove the sidebar and just use shortcuts, but I still find it useful.\u00a0 The context menu on the side bar out of the box on sublime is not the best, but <a href=\"https:\/\/packagecontrol.io\/packages\/SideBarEnhancements\">this package<\/a> enhances it a lot.<\/p>\n<h2>Snippets<\/h2>\n<p>One massive time saving part of sublime is snippets. \u00a0I&#8217;ve got various set up. \u00a0Lets walk through a quick example.<\/p>\n<p>So let&#8217;s just create a really simple multiplier method for php.<\/p>\n<pre class=\"lang:default decode:true\">private function multiplier(int $multiplier, float $value): float {\r\n\treturn $multiplier * $value;\r\n}\r\n<\/pre>\n<p>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:<br \/>\nTools &gt; Developer &gt; New Snippet<\/p>\n<p>and paste the following code in:<\/p>\n<pre class=\"lang:default decode:true\">&lt;snippet&gt;\r\n    &lt;content&gt;&lt;![CDATA[\r\n${1:private} function $2($3): ${4:string} {\r\n    $5\r\n}\r\n]]&gt;&lt;\/content&gt;\r\n    &lt;!-- Optional: Set a tabTrigger to define how to trigger the snippet --&gt;\r\n    &lt;tabTrigger&gt;cm&lt;\/tabTrigger&gt;\r\n    &lt;!-- Optional: Set a scope to limit where the snippet will trigger --&gt;\r\n    &lt;scope&gt;source.php&lt;\/scope&gt;\r\n&lt;\/snippet&gt;\r\n<\/pre>\n<p>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<br \/>\nUsing the extension .sublime-snippet, so i&#8217;ve just called mine method.sublime-snippet.<\/p>\n<p>So now in your project type cm and then press tab and you will get the following:<\/p>\n<pre class=\"lang:default decode:true\">private function (): string {\r\n    \r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">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.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4580\" src=\"https:\/\/www.bronco.co.uk\/our-ideas\/wp-content\/uploads\/2017\/10\/snippet-method.gif\" alt=\"snippet-method\" width=\"1243\" height=\"602\" \/><\/p>\n<p>Above is a coding php example but it can be used for any other language, especially front end development.\u00a0 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.<\/p>\n<h2>Other Features<\/h2>\n<h4>Split Screen<\/h4>\n<p>You can split sublime screen into a grid view, columns or rows by looking at \u201cView &gt; Layout\u201d however I don\u2019t tend to use this feature, although could be very useful when templating.<\/p>\n<h4>Vintage Mode<\/h4>\n<p>If you like Vi then switch this mode on (more information <a href=\"https:\/\/www.sublimetext.com\/docs\/3\/vintage.html\">here<\/a>)<\/p>\n<h4>Conclusion<\/h4>\n<p><i><\/i>This is a quick overview of how I have my editor setup.\u00a0 I\u2019m sure I\u2019m probably just using a fraction of what Sublime is capable of though.\u00a0 If you have an time saving methods or packages then why don\u2019t you comment below?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s fast, reliable, extendable and feature rich. I\u2019m hoping over the course of this post, you will learn something new or think of ways [&hellip;]<\/p>\n","protected":false},"author":24,"featured_media":4591,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"class_list":["post-4556","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-and-ux"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/posts\/4556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/comments?post=4556"}],"version-history":[{"count":0,"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/posts\/4556\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/media\/4591"}],"wp:attachment":[{"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/media?parent=4556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bronco.co.uk\/our-ideas\/wp-json\/wp\/v2\/categories?post=4556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}