Keyboard shortcut to jump to the non-whitespace first character in a line

keyboard

controla is pretty close – it moves the character to the first column. commandleft does too.

if my keyboard had a home key this would likely move the cursor there, but it doesn't.

similar to this question, i'm trying to get vim's ^ behaviour without moving my hands too far. unfortunately altm outputs µ instead of giving me the goods.

i'm hoping for something i can use system wide, i'm not sure if os x has this though.

Best Answer

There is no shortcut for it by default. As a hack, you can create ~/Library/KeyBindings/ and save a property list like this as ~/Library/KeyBindings/DefaultKeyBinding.dict:

{
  "~m" = (moveToBeginningOfParagraph:, insertText:, " ", moveLeft:, selectWord:, 
  moveRight:, setMark:, moveToBeginningOfParagraph:, deleteForward:, 
  swapWithMark:, moveLeft:);
}

Then quit and reopen applications to apply the changes. ~m is option-m, which is bound to back-to-indentation in Emacs.

I copied the macro from https://github.com/ttscoff/KeyBindings/blob/master/DefaultKeyBinding.dict. moveToBeginningOfParagraph:, selectWord:, moveRight: would not work with lines that don't start with spaces or tabs. moveToBeginningOfParagraph:,moveWordRight:, moveWordLeft: would not work with some lines where the first non-whitespace character is a special character.

DefaultKeyBinding.dict does not work with some applications like Xcode or Firefox.

See http://www.hcs.harvard.edu/~jrus/site/cocoa-text.html or http://osxnotes.net/keybindings.html for more information.