Skip to content

Instantly share code, notes, and snippets.

@romac
Created June 17, 2010 11:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romac/442009 to your computer and use it in GitHub Desktop.
Save romac/442009 to your computer and use it in GitHub Desktop.
Two Commands for TextMate which allows you to increment any digits/numbers in the selected text.
#!/usr/bin/env php
<?php
$text = $_ENV[ 'TM_SELECTED_TEXT' ];
print preg_replace_callback(
'/(\d)/',
function( $matches )
{
return $matches[ 0 ] + 1;
},
$text
);
#!/usr/bin/env php
<?php
$text = $_ENV[ 'TM_SELECTED_TEXT' ];
print preg_replace_callback(
'/(\d+)/',
function( $matches )
{
return $matches[ 0 ] + 1;
},
$text
);

Usage

  1. Create a new Command in some Bundle.
  2. Set Save to Nothing.
  3. Set Command(s) to the content of one of the Gist above.
  4. Set Input to: "Selected Text or Nothing".
  5. Set Output to Replace Selected Text.
  6. Set Activation to Key Equivalent and any keyboard shortcut you'd like to use (ie. ^I).
  7. Don't set a Scope Selector.
  8. It's done!
@t413
Copy link

t413 commented Jan 27, 2022

Amazing to find this relevant 12 years later! Thanks!

For TextMate 2 I did mostly the same thing, but to get it to work with multiple selection I had to make some changes.

Firstly go to menu, Bundles, Edit Bundles, then navigate to where you want this to live (I used Text -> Menu Actions). Use Cmd-N and select Command. Paste in this snippit and make change thins to be like my screenshot:

#!/bin/bash
while read line || [ -n "$line" ]; do 
  [ -z $line ] && break;
  ((line++));
  echo "$line";
done

Screen Shot 2022-01-27 at 2 44 38 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment