Three less-known Terminal tricks

23 January 2013, 02:00

Here are three less-known tricks for those who use the Terminal a lot.

1. Delete the word behind cursor: Ordinarily Terminal doesn’t obey the usual Option (Alt)+Delete* keystroke that deletes a word behind the cursor in other apps, or the Option+Left/Right combo that makes the cursor leap from word to word. As I mention in Mac Kung Fu, you can make Terminal do so by opening its preferences, clicking the Settings tab, selecting the Keyboard sub-tab and selecting Use Option as Meta Key. However, another way of deleting the word behind the cursor is to hit Escape, then Delete. You’ll need to do this for each word you want to delete — Escape, then Delete; Escape, then Delete; etc.

2. Move the cursor by clicking: If you’re editing a file in nano, emacs or vim you can hold down Option (Alt) then click anywhere in the file to move the cursor there. Yes, I know — this shouldn’t work. But it does! It works at the command line too — you can jump to anywhere in the line you’re currently typing by holding down Option and clicking there.

3. Use the mouse to cycle through your command history: This is a little hard to explain, but here goes: Holding down Option (Alt) at the command-prompt and clicking the line above the one you’re currently typing will cycle through your command history — just like tapping the Up cursor key. You can keep doing this to cycle through your entire history. However, clicking TWO lines up from the current command prompt will jump to the second command in the history — if the most recent command was ls, and the second cd ~, then you’d jump to cd ~. Clicking the third line jumps to the third command in your history, and so on. Clicking beneath the command-prompt does the same thing but in reverse. Give it a try!

Update:
Bonus fourth tip: To select a path or URL (i.e. /Users/keir/Desktop/, or http://apple.com), hold down Shift+Command and double-click it. It might sound like this is unnecessary but the usual trick of double-clicking doesn’t work because OS X gets confused by the slashes in the path. This only works in Terminal.

Bonus fifth tip: To reuse text you’ve already typed (or that is part of command output), just highlight it using the mouse then hit Shift+Command+V — no need to copy it first to the clipboard.

* On a Mac, “Delete” is what Apple calls the Backspace key. In other words, Delete is the key at the top right of all keyboards and it deletes things behind the cursor. The other delete key, in the home key cluster on full-size external keyboards, is the “Forward Delete” key in Apple-speak. Did you know Apple publishes a style guide?

Disagree? Tell me why...

 
---