Sublime Text 2 Shortcuts

Show PHP function list
  • CTRL+r
Clean up code
  • CTRL+ALT+t : HTMLTidy
  • CTRL+ALT+E : Encode special characters
Tag completion, folding
  • CTRL+. : close tag
  • CTRL+SHIFT+[ : Fold Code
  • CTRL+t : Fold Tag Attributes
  • <tag + TAB = autocompletion, e.g. <a + TAB = <a href=””></a>
  • <tag> + ALT + . = autocompletion, eg. <a> + ALT + . = <a></a>
Find in file(s)
  • CTRL+F : Find in file
  • CTRL+SHIFT+F : Find in files (or right click on folder and click Find in Folder)
  • CTRL+H : Find and replace in file

HOSTS File: Change an External Domain to Point Somewhere Else

If you update your hosts file to point a domain to another location, accessing that domain will take you to your new destination. For example, in Windows, your hosts file is at

C:WindowsSystem32driversetchosts

If you add the following:

127.0.0.1 www.google.com

and then open your browser and go to www.google.com, you will not see Google’s home page but rather your local host index page.  This can be handy when you want to disable one javascript include in a page that you don’t have access to. By pointing the external javascript domain to your local host, a 404 not found will be triggered which will prevent the code from running. Everything else, including other references to external javascript files,  in the page will still continue to execute.

Debugging Javascript Errors in jQuery or 3rd Party Javascript Libraries

When you’re righting some Javascript / jQuery and run your code, you normally would see your errors in your browser inspector’s console tab so you can easily fix them. But, sometimes the error you see appears in 3rd party code that you haven’t even touched, e.g. jQuery. One way to find where the “real” error has occurred is by looking at the call stack. In Chrome Inspector, do the following:

  1. Click the Sources tab
  2. Click the Stop sign until it is purple (Pause at all uncaught exceptions)
  3. Reload the page
  4. Examine the call stack

Filtering Text By Line / Remove All Lines Except Ones That Contain A String

Usually I need to find and replace strings with other strings, which is easy to do using your standard “Find and Replace” function in your text editor. But, oftentimes I also need to find certain lines of text and remove everything EXCEPT them.  Trying to write a regex to search and replace everything BUT a particular string is complicated. An easier way is to just use the unix command “grep”. For example, if you want to extract all lines in a file called report.txt that contain the word “time” in them, you can do

$ grep ‘time’ report.txt

If you want to output the result of this filtering to a file, you can run

$ grep ‘time’ report.txt > filtered-report.txt

If you want to extract certain pieces of text in each line of a file called report.txt where those pieces of text are offset from the beginning of each line based on certain delimiters, e.g. commas, tabs, spaces, then you can use the awk command.