Can anyone help with a command that would convert the case of selected text as well as replaced spaces with underscores?
So, for instance:
This is a Title -> this_is_a_title
As a complete beginner in TextMate, I'm not sure how to create a command to do this. Any help would be greatly appreciated.
Best, Michael R.
On 19.11.2008, at 19:25, Michael Reiner wrote:
Can anyone help with a command that would convert the case of selected text as well as replaced spaces with underscores?
So, for instance:
This is a Title -> this_is_a_title
As a complete beginner in TextMate, I'm not sure how to create a command to do this.
There're many ways. Maybe the simplest - record a macro:
- type 'This is a Title' and select it
- Bundles > Macro > Start Recording
- Text > Convert > to Lowercase
- Edit > Find > Find [APPLE+F]
– Find: ' ' (a space) Replace: '_'
Hold down OPTION key and execute 'In Selection'
- Bundles > Macro > Stop Recording
- Bundles > Macro > Save Last Recording
That's it. You can maybe assign a shortcut to the macro of course.
--Hans
here's my attempt. just double click the bundle to install. should convert all characters to lowercase then add underscores instead of spaces. I don't know why it's inserting the newline though. if someone knows how to use sed they could make a better command.
hope this helps!
-Nick
On Wed, Nov 19, 2008 at 10:43 AM, Hans-Jörg Bibiko bibiko@eva.mpg.dewrote:
On 19.11.2008, at 19:25, Michael Reiner wrote:
Can anyone help with a command that would convert the case of selected text as well as replaced spaces with underscores?
So, for instance:
This is a Title -> this_is_a_title
As a complete beginner in TextMate, I'm not sure how to create a command to do this.
There're many ways. Maybe the simplest - record a macro:
type 'This is a Title' and select it
Bundles > Macro > Start Recording
Text > Convert > to Lowercase
Edit > Find > Find [APPLE+F]
– Find: ' ' (a space) Replace: '_'
Hold down OPTION key and execute 'In Selection'
Bundles > Macro > Stop Recording
Bundles > Macro > Save Last Recording
That's it. You can maybe assign a shortcut to the macro of course.
--Hans
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 19.11.2008, at 21:55, Nick wrote:
here's my attempt. just double click the bundle to install. should convert all characters to lowercase then add underscores instead of spaces. I don't know why it's inserting the newline though. if someone knows how to use sed they could make a better command.
Only for the records, I would suggest to use this to avoid printing a newline:
/usr/bin/env php -r ' print(strtolower(str_replace(" ", "_", $_ENV["TM_SELECTED_TEXT"]))); '
AND please note that this is not Unicode safe, maybe in PHP 6.0!
--Hans