Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm looking to be able to select the current word my text cursor is inside on OSX (10.7.3).

For people who have used vim before, I want to be able to do a similar thing to the 'ci_' command, where '_' can be 'w', '(', '[', etc. to specify deleting the word or contents of a parens/bracket and enter insert mode.

The best way I've figured to do this is Option+Left then Shift+Option+Right to first navigate to the left end of the word, then select to its right end. Is there a way I can create a macro to do both of these at once?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

This has been covered in a screencast on the Ask Different Blog. I encourage you to watch the video, but I'll summarize here.

First, create a little AppleScript that presses the two keyboard shortcuts. Open AppleScript Editor (in /Applications/Utilities) and paste this in:

tell application "System Events"
    key code 123 using option down
    key code 124 using {shift down, option down}
end tell

Save that as a script in ~/Library/Scripts (create the folder if it doesn't already exist).

Now, install the app FastScripts. It's free for up to 10 scripts.
Open the FastScripts preferences, find your Select Word script, and assign a keyboard shortcut to it.

Now you can press your chosen shortcut in any app and the current word will be selected.

share|improve this answer
    
Thanks loads for the link, I appreciate it! –  JKomusin Mar 18 '12 at 22:08
add comment

Another option would be to create ~/Library/KeyBindings/ and save a property list like this as DefaultKeyBinding.dict:

{
    "~w" = selectWord:; // option-w
}

The custom keybindings don't work in some cross-platform applications (or currently Xcode), but they don't have any perceivable delays like AppleScripts or Keyboard Maesto macros.

For more information, see hcs.harvard.edu/~jrus/Site/Cocoa Text System.html, lri.me/keybindings, and brettterpstra.com/tag/keybindings.

share|improve this answer
    
Unfortunately Xcode is where I'd most prefer to use these bindings. But the delay-free aspect is interesting! Thanks (I'd up vote, but my low rep on this exchange won't allow me) –  JKomusin Mar 20 '12 at 17:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.