By josh / May 9, 2013

How to delete lines that start with a given set of characters

Subscriber Alex recently asked whether there’s a good way to remove lines starting with a given set of characters.

I’m not aware of a built-in feature that does exactly that in one step, but it’s pretty easy to accomplish.

Here’s how:

  • Click Find | Find.
  • Switch to regular expression mode by clicking the button labeled with a tiny asterisk (it’s the leftmost one).
  • Enter ^, followed by your search term. The caret mark will restrict searches to only matches that fall at the beginning of a line.
  • Click Find All.
  • Use Expand Selection to Line to select all of the lines.
  • Hit Delete.

Not as graceful as a single click or keyboard shortcut, but it’ll get the job done.

Plugin of the Week

I wish I’d had a tool like the Sublime phpcs plugin when I was pecking out my first lines of PHP. Out of the box it’ll check your code for errors every time you save a file, and it gives you a Command Palette-style list so you can jump from typo to typo. It’ll also run other useful code checkers like PHP Code Sniffer, PHP Mess Detector and Scheck.

How-To & Interesting Articles

Starting a New WordPress Plugin with Sublime Text

Sublime Text Resources for Front End Developers

Setting Up Sublime Text

P.S. You can get more great Sublime tricks in the Sublime Text Tips newsletter. Sign up here today:

About the author


Click here to add a comment

Leave a comment: