• Posted by Peter Haza
  • On August 9, 2008

  • Filed under TextMate

  • 4 Comments

TextMate tip: Go to first non-space character on current line

One small thing that has always bugged me with TextMate is that ⌘← goes to the beginning of the line, instead of what I prefer: the first non-space character on the line. Well, thanks to “Jacobolous” in ##textmate@irc.freenode.net, that’s not a problem anymore.

This command has been updated, you can read what was changed here.

You can now download the command here: Go To First Non-Whitespace Character

It’s actually very easy to sort out, and even though I’ve thought about fixing this before, I never managed to wrap my head around it. The whole solution is to record a macro, and it takes you about 40 seconds. The whole procedure is as follows in TextMate:

  • Press ⌥⌘M to start recording a macro
  • Press ⌘← to go to the beginning of the line
  • Press ⌘F and search for [^\s]|\n with regular expressions enabled (Thanks to Abhi Beckert)
  • Press ← to go to beginning of selection(unselecting)
  • Press ⌥⌘M to stop recording the macro.
  • Press ⌃⌘M to save your macro
  • Give the macro a name and a key equivalent (I used ⌘← to overwrite the normal go to beginning of line behaviour)

Done!

4 comments

  1. Posted by Chris 6th September, 2008 at 05:23 am |

    Excellent, thank you

  2. Posted by Abhi Beckert 13th September, 2008 at 07:07 pm |

    “Why didn’t I think of that?” Fantastic tip! thanks :)

  3. Posted by Abhi Beckert 16th September, 2008 at 02:13 am |

    I’m now using ([^\s]|\n) as the regex pattern, which functions as expected on empty lines and lines with only whitespace.

  4. Posted by Falk 19th October, 2010 at 08:03 am |

    Thank you.

What do you think? Join the discussion...