I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number.
Here is my current replacement string: $1##$2
How can I replace the ## with a sequential number?
For example, I want the first sequential number to be 16.
Here is a screen capture: http://textmate.1073791.n5.nabble.com/file/n28976/16562519926_345a547ff1_o.png
Thanks!
-- View this message in context: http://textmate.1073791.n5.nabble.com/How-can-I-add-a-sequencial-number-to-t... Sent from the textmate users mailing list archive at Nabble.com.
Hi jgaltUSA,
On 20 Feb 2015, at 9:50 , jgaltUSA jgaltUSA@gmail.com wrote:
I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number.
Here is my current replacement string: $1##$2
How can I replace the ## with a sequential number?
I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want:
#!/usr/bin/env python
from re import compile from sys import stdin, stdout
regex = compile( """(<PortalOBj portalFlags="16" numbOfRows="1" initialRow=")\d+(">)""") index = 16
def create_subtitute_function(): def substitute(match): global index replacement = "{}{}{}".format(match.group(1), index, match.group(2)) index += 1 return replacement
return substitute
text = regex.sub(create_subtitute_function(), stdin.read()) stdout.write(text)
I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :).
For example, I want the first sequential number to be 16.
Here is a screen capture:
Thanks!
Kind regards, René
P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture.
You can combine Multiple Carets and Copy + Paste to achieve this easily.
Find a list of the numbers you want to use, I assume you’re capable of generating the list in some way, but I like using the `seq` command in the terminal such as:
$ seq 16 32 16 17 […snip...] 31 32
Note: It is important that they be separated by new line characters.
Copy this list.
Select your first placeholder: “##"
<PortalOBj portalFlags="16" numbOfRows="1" initialRow=“##”>
Press Control + W, this selects the next placeholder. Repeat until your selection contains all of your placeholders.
Paste.
Graham P Heath
On February 20, 2015 at 8:29:30 AM, René Schwaiger (sanssecours@f-m.fm) wrote:
Hi jgaltUSA,
On 20 Feb 2015, at 9:50 , jgaltUSA jgaltUSA@gmail.com wrote: I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number. Here is my current replacement string: $1##$2 How can I replace the ## with a sequential number?
I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want:
#!/usr/bin/env python
from re import compile from sys import stdin, stdout
regex = compile( """(<PortalOBj portalFlags="16" numbOfRows="1" initialRow=")\d+(">)""") index = 16
def create_subtitute_function(): def substitute(match): global index replacement = "{}{}{}".format(match.group(1), index, match.group(2)) index += 1 return replacement
return substitute
text = regex.sub(create_subtitute_function(), stdin.read()) stdout.write(text)
I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :).
For example, I want the first sequential number to be 16. Here is a screen capture: Thanks!
Kind regards, René
P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture.
_______________________________________________ textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Thanks Graham, that worked great but I am having one problem. The first line of your formula gets placed into my first placeholder.
Example: <PortalObj portalFlags="16" numOfRows="1" initialRow=$ seq 16 32>
On 2/20/15 9:41 AM, "Graham P Heath" graham.p.heath@gmail.com wrote:
You can combine Multiple Carets and Copy + Paste to achieve this easily.
Find a list of the numbers you want to use, I assume you’re capable of generating the list in some way, but I like using the `seq` command in the terminal such as:
$ seq 16 32 16 17 […snip...] 31 32
Note: It is important that they be separated by new line characters.
Copy this list.
Select your first placeholder: “##"
<PortalOBj portalFlags="16" numbOfRows="1" initialRow=“##”>
Press Control + W, this selects the next placeholder. Repeat until your selection contains all of your placeholders.
Paste.
Graham P Heath
On February 20, 2015 at 8:29:30 AM, René Schwaiger (sanssecours@f-m.fm) wrote:
Hi jgaltUSA,
On 20 Feb 2015, at 9:50 , jgaltUSA jgaltUSA@gmail.com wrote: I am a newbie to textmate and I am trying to perform a find and replace. I
want to replace the matched text with a sequential number.
Here is my current replacement string: $1##$2 How can I replace the ## with a sequential number?
I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want:
#!/usr/bin/env python from re import compile from sys import stdin, stdout regex = compile( """(<PortalOBj portalFlags="16" numbOfRows="1"
initialRow=")\d+(">)""") index = 16
def create_subtitute_function(): def substitute(match): global index replacement = "{}{}{}".format(match.group(1), index,
match.group(2)) index += 1 return replacement
return substitute text = regex.sub(create_subtitute_function(), stdin.read()) stdout.write(text)
I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :).
For example, I want the first sequential number to be 16. Here is a screen capture: Thanks!
Kind regards, René
P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Don’t copy that line. Just its results.
16 17 […snip...] 31 32 Graham P Heath
On February 20, 2015 at 1:16:44 PM, jgalt (jgaltusa@gmail.com) wrote:
Thanks Graham, that worked great but I am having one problem. The first line of your formula gets placed into my first placeholder.
Example: <PortalObj portalFlags="16" numOfRows="1" initialRow=$ seq 16 32>
On 2/20/15 9:41 AM, "Graham P Heath" graham.p.heath@gmail.com wrote:
You can combine Multiple Carets and Copy + Paste to achieve this easily.
Find a list of the numbers you want to use, I assume you’re capable of generating the list in some way, but I like using the `seq` command in the terminal such as:
$ seq 16 32 16 17 […snip...] 31 32
Note: It is important that they be separated by new line characters.
Copy this list.
Select your first placeholder: “##"
<PortalOBj portalFlags="16" numbOfRows="1" initialRow=“##”>
Press Control + W, this selects the next placeholder. Repeat until your selection contains all of your placeholders.
Paste.
Graham P Heath
On February 20, 2015 at 8:29:30 AM, René Schwaiger (sanssecours@f-m.fm) wrote: Hi jgaltUSA,
On 20 Feb 2015, at 9:50 , jgaltUSA jgaltUSA@gmail.com wrote: I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number. Here is my current replacement string: $1##$2 How can I replace the ## with a sequential number?
I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want:
#!/usr/bin/env python
from re import compile from sys import stdin, stdout
regex = compile( """(<PortalOBj portalFlags="16" numbOfRows="1" initialRow=")\d+(">)""") index = 16
def create_subtitute_function(): def substitute(match): global index replacement = "{}{}{}".format(match.group(1), index, match.group(2)) index += 1 return replacement
return substitute
text = regex.sub(create_subtitute_function(), stdin.read()) stdout.write(text)
I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :).
For example, I want the first sequential number to be 16. Here is a screen capture: Thanks!
Kind regards, René
P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture.
_______________________________________________ textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
_______________________________________________ textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
_______________________________________________ textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Thank you very much. That worked.
Sorry, I missed the part about entering ³$ seq 16 32² as a terminal command.
On 2/20/15 2:35 PM, "Graham P Heath [via TextMate]" ml-node+s1073791n28980h88@n5.nabble.com wrote:
Don¹t copy that line. Just its results.
16 17 [snip...] 31 32
-- View this message in context: http://textmate.1073791.n5.nabble.com/How-can-I-add-a-sequencial-number-to-t... Sent from the textmate users mailing list archive at Nabble.com.
Graham, thanks for the heads up regarding the terminal commands in Textmate. This is a great feature!
On 2/20/15 9:41 AM, "Graham P Heath" graham.p.heath@gmail.com wrote:
but I like using the `seq` command in the terminal such as:
$ seq 16 32
On 20 Feb 2015, at 22:41, Graham P Heath wrote:
You can combine Multiple Carets and Copy + Paste to achieve this easily.
Find a list of the numbers you want to use, I assume you’re capable of generating the list in some way, but I like using the `seq` command in the terminal such as: […]
In 2.0-beta.7 I streamlined this so that running `seq` via Filter Through Commmand… behaves the same as pasting, bypassing the need to go to a Terminal and copying the command output.
Thanks for taking the time to create the bundle for me René.
I have installed it but I am not 100% sure how to use it.
I have entered the shortcut key command “^⌥⌘R” and it appears to run but I do not understand how to target the parts that I want to replace.
Here is a screen capture of my find and replace settings: http://goo.gl/YBqYy9
Here is a zipped file of the file that I am trying to edit: http://goo.gl/XOkDRh
I don't know if it matters...but the content that I am trying to edit is from a FileMaker clipboard. I believe that it is in XML format. The items that I am trying to edit are references to layout elements. (More specifically, references to FileMaker Portals.)
Thanks again for your help!
On 2/20/15 8:26 AM, "René Schwaiger" sanssecours@f-m.fm wrote:
Hi jgaltUSA,
On 20 Feb 2015, at 9:50 , jgaltUSA jgaltUSA@gmail.com wrote:
I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number.
Here is my current replacement string: $1##$2
How can I replace the ## with a sequential number?
I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want:
#!/usr/bin/env python from re import compile from sys import stdin, stdout regex = compile( """(<PortalOBj portalFlags="16" numbOfRows="1"
initialRow=")\d+(">)""") index = 16
def create_subtitute_function(): def substitute(match): global index replacement = "{}{}{}".format(match.group(1), index,
match.group(2)) index += 1 return replacement
return substitute text = regex.sub(create_subtitute_function(), stdin.read()) stdout.write(text)
I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :).
For example, I want the first sequential number to be 16.
Here is a screen capture:
Thanks!
Kind regards, René
P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture.

textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Sorry, my previous example file was not formatted properly and it got truncated. Here is a revised example file as XML: http://goo.gl/el0QMT
On 2/20/15 2:45 PM, "jgalt" jgaltusa@gmail.com wrote:
Thanks for taking the time to create the bundle for me René.
I have installed it but I am not 100% sure how to use it.
I have entered the shortcut key command “^⌥⌘R” and it appears to run but I do not understand how to target the parts that I want to replace.
Here is a screen capture of my find and replace settings: http://goo.gl/YBqYy9
Here is a zipped file of the file that I am trying to edit: http://goo.gl/XOkDRh
I don't know if it matters...but the content that I am trying to edit is from a FileMaker clipboard. I believe that it is in XML format. The items that I am trying to edit are references to layout elements. (More specifically, references to FileMaker Portals.)
Thanks again for your help!
On 2/20/15 8:26 AM, "René Schwaiger" sanssecours@f-m.fm wrote:
Hi jgaltUSA,
On 20 Feb 2015, at 9:50 , jgaltUSA jgaltUSA@gmail.com wrote:
I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number.
Here is my current replacement string: $1##$2
How can I replace the ## with a sequential number?
I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want:
#!/usr/bin/env python from re import compile from sys import stdin, stdout regex = compile( """(<PortalOBj portalFlags="16" numbOfRows="1"
initialRow=")\d+(">)""") index = 16
def create_subtitute_function(): def substitute(match): global index replacement = "{}{}{}".format(match.group(1), index,
match.group(2)) index += 1 return replacement
return substitute text = regex.sub(create_subtitute_function(), stdin.read()) stdout.write(text)
I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :).
For example, I want the first sequential number to be 16.
Here is a screen capture:
Thanks!
Kind regards, René
P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture.

textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
What on earth am I doing wrong with my sample files? After I save them and try to reopen them in TextMate they are blank...but if I open it in a different text editor all of the content is still there.
On 2/20/15 2:57 PM, "jgalt" jgaltusa@gmail.com wrote:
Sorry, my previous example file was not formatted properly and it got truncated. Here is a revised example file as XML: http://goo.gl/el0QMT
On 2/20/15 2:45 PM, "jgalt" jgaltusa@gmail.com wrote:
Thanks for taking the time to create the bundle for me René.
I have installed it but I am not 100% sure how to use it.
I have entered the shortcut key command “^⌥⌘R” and it appears to run but I do not understand how to target the parts that I want to replace.
Here is a screen capture of my find and replace settings: http://goo.gl/YBqYy9
Here is a zipped file of the file that I am trying to edit: http://goo.gl/XOkDRh
I don't know if it matters...but the content that I am trying to edit is from a FileMaker clipboard. I believe that it is in XML format. The items that I am trying to edit are references to layout elements. (More specifically, references to FileMaker Portals.)
Thanks again for your help!
On 2/20/15 8:26 AM, "René Schwaiger" sanssecours@f-m.fm wrote:
Hi jgaltUSA,
On 20 Feb 2015, at 9:50 , jgaltUSA jgaltUSA@gmail.com wrote:
I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number.
Here is my current replacement string: $1##$2
How can I replace the ## with a sequential number?
I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want:
#!/usr/bin/env python from re import compile from sys import stdin, stdout regex = compile( """(<PortalOBj portalFlags="16" numbOfRows="1"
initialRow=")\d+(">)""") index = 16
def create_subtitute_function(): def substitute(match): global index replacement = "{}{}{}".format(match.group(1), index,
match.group(2)) index += 1 return replacement
return substitute text = regex.sub(create_subtitute_function(), stdin.read()) stdout.write(text)
I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :).
For example, I want the first sequential number to be 16.
Here is a screen capture:
Thanks!
Kind regards, René
P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture.

textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 21 Feb 2015, at 7:10, jgalt wrote:
What on earth am I doing wrong with my sample files? After I save them and try to reopen them in TextMate they are blank...but if I open it in a different text editor all of the content is still there.
Can you give (exact) steps to reproduce for this issue?
I just opened the file that was giving me trouble and it opened normally. I am not sure what fixed the problem but it was either rebooting my computer or updating from an older beta to (2.0-beta.6.8).
To answer your question, the document appeared to blank when I opened it Textmate but when I opened it in a different text editor all of the content was still there. If it happens again I will make a screencast.
Thanks.
On 2/21/15 11:35 PM, "Allan Odgaard-4 [via TextMate]" ml-node+s1073791n28987h5@n5.nabble.com wrote:
On 21 Feb 2015, at 7:10, jgalt wrote: > What on earth am I doing wrong with my sample files? After I save them and > try to reopen them in TextMate they are blank...but if I open it in a > different text editor all of the content is still there. Can you give (exact) steps to reproduce for this issue? _______________________________________________ textmate mailing list [hidden email] </user/SendEmail.jtp?type=node&node=28987&i=0> http://lists.macromates.com/listinfo/textmate
-- View this message in context: http://textmate.1073791.n5.nabble.com/How-can-I-add-a-sequencial-number-to-t... Sent from the textmate users mailing list archive at Nabble.com.
Hi,
On 20 Feb 2015, at 21:57 , jgalt jgaltusa@gmail.com wrote:
Sorry, my previous example file was not formatted properly and it got truncated. Here is a revised example file as XML: http://goo.gl/el0QMT
Could it be that the first and second uploads are the same file? They have the same file size, modification date and md5 hash:
MD5 (jgalt_replacement_example.zip) = c25e2dad9e95a3ce2d00c26fda8f14f4 MD5 (jgalt_replacement_example_v2.zip) = c25e2dad9e95a3ce2d00c26fda8f14f4
On 20 Feb 2015, at 21:45 , jgalt jgaltusa@gmail.com wrote:
Thanks for taking the time to create the bundle for me René.
I have installed it but I am not 100% sure how to use it.
I have entered the shortcut key command “^⌥⌘R” and it appears to run but I do not understand how to target the parts that I want to replace.
The command reads the current selection — if there is none, then it reads the whole file — and replaces every occurrence of the regex with the result of the first capture (`match.group(1)`), followed by a sequential number (`index`), and the result of the second capture (`match.group(2)`).
Which part are targeted depends on your selection and the regex. Since there were two minor mistakes in the regex it should not have replaced anything for you. To fix the regex:
1. Open the bundle editor `^⌥⌘B` 2. Go to Subsitute→Menu Actions→Subsitute 3. Replace
"""(<PortalOBj portalFlags="16" numbOfRows="1" initialRow=")\d+(">)"""
with the correct regex (`PortalObj` instead of `PortalOBj`, `numOfRows` instead of `numbOfRows`):
"""(<PortalObj portalFlags="16" numOfRows="1" initialRow=")\d+(">)"""
4. Save the changes `⌘S`
The zip you sent contained a screenshot of a file, where you wanted to replace the number 1-15 with the numbers 16-30. If you want to do that you can just replace the regex with the following:
"""(<PortalObj portalFlags="16" numOfRows="1" initialRow=")(?:[1-9]|1[0-5])(">)"""
It should not do anything on the file you sent though, since that contained `initialRow` numbers ranging from 31-45.
Here is a screen capture of my find and replace settings: http://goo.gl/YBqYy9
Here is a zipped file of the file that I am trying to edit: http://goo.gl/XOkDRh
I don't know if it matters...but the content that I am trying to edit is from a FileMaker clipboard. I believe that it is in XML format. The items that I am trying to edit are references to layout elements. (More specifically, references to FileMaker Portals.)
Thanks again for your help!
Kind regards, René