Archive for the 'General' Category

Xcode trick: Creating a shortcut to duplicate a line

Friday, May 14th, 2010

A feature I love in TextMate that is missing in Xcode is the ability to duplicate a line of text with a simple two-key combo. Sure, it’s possible to select the line and then copy/paste, but it’s far too fiddly. For example, let’s say I wanted to add another line to this array:

xcode-duplicate-line-1.png

I would have to type:

+ move to start of line

+ (shift-down) select line

+ C copy

(down) (deselect)

+ V paste

And I would end up with this.

xcode-duplicate-line-2.png

That’s far too much work.

Digging through Xcode’s preferences I couldn’t find anything that would help, so I widened my search and stumbled on a page called Customizing the Cocoa Text System that showed me a way I could get this to work.

I created a directory:

mkdir ~/Library/KeyBindings

And created the file:

~/Library/KeyBindings/DefaultKeyBinding.dict

{
    "^d" = ("moveToEndOfLine:",
        "deleteToBeginningOfLine:", // line in kill buffer
        "yank:", // put back what was deleted
        "insertLineBreak:",
        "moveToBeginningOfLine:",
        "yank:"); // duplicate line
}

I restarted Xcode, and now a control+D (^d) duplicates the line. And I can easily add the new element to the array.

xcode-duplicate-line-3.png

And it’s a system wide change, so it will work in many applications that have text input. (And doesn’t seem to screw up TextMate either.)

If you want to experiment with your own text input tweaks, there is a list of all selectors. You’ll need to restart whatever application you’re using to test after each change. You may also run into strange side effects. I ran into a problem with Xcode doing auto-intent after i added a newline with insertNewline:. Luckily, insertLineBreak: has the same effect, but seems to trick Xcode into not adding the extra whitespace on the duplicated line.

Protected: Browser Activity: When to provide explicit status feedback

Thursday, October 25th, 2007

This post is password protected. To view it please enter your password below:

Protected: Thematic maps: Adjusting the number of gradients and colors for maximum usability

Thursday, October 11th, 2007

This post is password protected. To view it please enter your password below:

Attack of the ‘Click Here’ links

Thursday, May 31st, 2007

I am amused by the click here style of links, since they are clearly BadDesign™ but they persist. Sure you expect to find them on pre-2000 webpages, ebay listings and the like, but even high-profile professional sites fall into the seductive click here trap.

Check this out from the Globe and Mail this morning:

Click Here - Screenshot from the theglobeandmail.com

Of course, a much better way of adding a link (assuming you want people to click on it) is to remove the mini-tutorial about how you need to click on links and put the verb first. This makes it a shorter, more compelling call to action. For example:

Comment on the discussion

I just created a Click Here! tag. I’m going to post the best offenders that I run across.