[TxMt] Block / Line commenting

Allan Odgaard allan at macromates.com
Mon Nov 15 12:46:03 UTC 2004

On 15. Nov 2004, at 13:20, Brian Gorby wrote:

> Is there a way in v1.0.1 to highlight a line or a block and have it 
> either commented or uncommented based on the current state of the line 
> (a la Scite)? Could this be done through the use of Macros?

You can do a macro that does a regex replace in the selection. For 
example if you search for: “^(#)?(.*)$” it will match the line and 
place the leading # in capture register 1, if it exists. In the format 
string you can check whether capture register 1 captured anything and 
do conditional replacements, so make the replace string e.g. like this: 
“?1$2:#$2”. This will put a # in front of the line if it didn't already 
have one, otherwise it will remove it.

An alternative would be simply to pipe the selection through a script 
which does similar, I think such a script is available from the wiki 
(this could then be a command, which is probably easier to edit later, 
if you need to change it).

More information about the textmate mailing list