I found out today that there are several other students at Nashville Software School that are reading this blog. I figure that means this is a good opportunity to throw some general tips out there for others that are starting out.
I tend to find shortcuts for many things and we certainly won’t be covering them all in class. So, for those enterprising enough to be reading another classmate’s blog, here are some of the things that I use to speed up my workflow:
We’ll start with some basics:
Alt+Tab – This is a very well known keyboard shortcut to switch between open applications. Hold down Alt and press Tab repeatedly to select the application you wish to work in. Add shift to move in the opposite direction.
Ctrl+Tab – This does the same thing as Alt+Tab, but for windows within an application. This is very helpful for switching between files in Sublime.
F5 – Refresh your browser window.
Alt+D – Put the cursor in the address bar of your browser. It should highlight the entire address as well.
Now some helpful Sublime shortcuts:
Ctrl+/ – Comment/uncomment current line. You can also highlight specific text before doing this to comment only that text (doesn’t work in all types of files).
Ctrl+L – Select entire current line and places cursor at the beginning of the next line. Keep hitting it to select lines below it. If you hit delete, the remaining lines collapse against each other.
Multi-Line editing in Sublime:
This is one of the most unbelievable timesavers. Say you have to write the same thing in many places. Or maybe you decided to change a variable name and want to change all instances of the previous variable name. There are a couple ways that you can do this.
Hold Ctrl and click everywhere that you want a cursor. That’s right, you can have dozens of cursors and whatever you type will show up everywhere you placed a cursor. Every time you hit backspace, every cursor will delete a character. Where it gets really interesting is that you can hit Home or End and every cursor will go to either end of their respective lines, regardless of length. That allows you to easily nest strings inside methods on multiple lines. Additionally, each cursor has it’s own clipboard, so you could potentially copy and paste a dozen different things all at once.
Another way to use this is to highlight some text that occurs everywhere that you want a cursor. Then every time you hit Ctrl+D, the next place that text appears will be selected and a cursor placed there. Use Alt+F3 to select all instances.
Using either method, use Esc to get back to a single cursor. The cursor closest to the top of the document will become your single cursor.
Terminal:
In class, we’ve been naming our project folders like 2013-09-26-Restaurant-Menu. It’s really descriptive, but can make navigating to various directories in terminal really tedious. For these things, it’s really important to remember the wildcard operator *
cd *Menu
is the same as
cd 2013-09-26-Restaurant-Menu
Also, we now have our Haml/Sass/JS template. That folder name is 2013-09-23-HAML-SASS-JS-Template, which you don’t really want to type in every time that we need to copy that folder for a new project. So what I’ve been doing is the following:
cp -r *JS* 2013-09-26-Restaurant-Menu
I should note that if there are multiple directories that match the bit of text that you specify, it will simply pick the first one it comes to. So make sure that you use text that is unique to the directory that you really want to access or copy.
Do you find yourself making a directory and then needing to go into it, like this?
mkdir New-Directory
cd New-Directory
You can do that all in one command, just add the following to your ~/.bash_profile file:
alias mkcd=’_(){ mkdir $1; cd $1; }; _’
That will allow you to do the above lines like this:
mkcd New-Directory
Most of these are things that I find myself using every day and almost take for granted. Hopefully everyone at NSS who reads this will be able to get some use out of these easy methods for speeding up your workflow.