Page 1 of 1

Selecting a Single Word

Posted: 2011-07-07 09:04:58
by bjast
Is anyone aware of a macro that will select the entire word by simply having the cursor placed somehwhere within that word?

This would make text editing a whole lot easier.

Thanks

Re: Selecting a Single Word

Posted: 2011-07-07 09:24:02
by martin
If you double-click any bit of text, the selection will expand to include the whole word that was clicked.

However, if you'd like to use a macro, here's one:

Code: Select all

Send Selector ‘selectWord:’
That uses a bit of magic (Cocoa's "selectWord:" selector), and I was hoping for a more reusable example, but strangely our macro language is missing a "rangeOfWordAtIndex" command, which would be the most straightforward.

Here's another macro that also selects the whole word. It uses regular expressions, which may or may not be clearer for you:

Code: Select all

Find Previous '\b', 'E'
Find Next '\w+', 'E'

Re: Selecting a Single Word

Posted: 2011-07-07 10:11:06
by bjast
Thanks Martin.

As usual you came through with just what I needed.

This tip will be used by me many thousands of time in the coming years!

Bill