TW5 Search and replace within text

459 views
Skip to first unread message

StephanF

unread,
Jun 4, 2017, 1:28:56 PM6/4/17
to tiddl...@googlegroups.com
Thanks in advance for your help!

I have a bunch of tiddlers all tagged 'x' that have 'abc' in the text. I would like to replace 'abc' with 'xyz' in all these tiddlers without disturbing the rest of the text.

The actual case is to replace some standard text with  the appropriate wikitext to transclude a template that shows field values. I have the template working just fine, but would have to manually edit all the existing tiddlers to replace the standard text with the template transclusion.

Thanks again!
Stephan

Mat

unread,
Jun 4, 2017, 5:06:01 PM6/4/17
to TiddlyWiki
If you're OK with a one-off solution rather than a general way, I'd suggest using a separate editor (e.g Notepad++ ) and do a search and replace.

<:-)

StephanF

unread,
Jun 4, 2017, 5:58:08 PM6/4/17
to TiddlyWiki
Thanks Mat!
as it happens I wound up doing exactly that using WordPad on a windows8.1 machine. BUT it felt like cheating, so am still hopeful of discovering a solution within TW5
Regards,
Stephan

@TiddlyTweeter

unread,
Jun 5, 2017, 7:22:17 AM6/5/17
to TiddlyWiki
Ciao StephanF

There IS at least one plugin, I think, that does global search and replace. I'm trying to find it.

A footnote: BTW, if you are using Firefox, inside the TW editor you can directly invoke any external program you want by installing the It's All Text Add-On for Firefox. That Firefox plugin saves a temporary copy of the edit area to a file, opens the application for it you assign, detects when the file changes & updates the edit area. I use it both for external SVG editing in a graphics program and for simple text editing in a full featured text editor that supports regex. But, of course, you are not going to get global regex that way, just the one tiddler.

Best wishes
Josiah

StephanF

unread,
Jun 5, 2017, 3:15:40 PM6/5/17
to TiddlyWiki
thanks!

Stephan Hradek

unread,
Aug 26, 2017, 7:06:00 PM8/26/17
to TiddlyWiki
A quite old question.

Here is a (kind of) solution with vanilla TW5:

\define settext() $(start)${{$:/state/sr!!replace}}$(right)$

Search: <$edit tiddler="$:/state/sr" field="search"/>

Replace: <$edit tiddler="$:/state/sr" field="replace"/>

<$list filter="[tag[x]]" variable="replaceHere">

<$link to=<<replaceHere>>><$view tiddler=<<replaceHere>> field="title"/></$link>

<$list filter="[title<replaceHere>get[text]splitbefore{$:/state/sr!!search}]" variable="left">

<$list filter="[title<replaceHere>get[text]removeprefix<left>]" variable="right">

<$list filter="[<left>] +[removesuffix{$:/state/sr!!search}]" variable="start">

<<start>> <$button>
<$action-setfield $tiddler=<<replaceHere>> $field="text" $value=<<settext>>/>
{{$:/
state/sr!!replace}}
</$button> <<right>>

</
$list>

</$list>

</
$list>

The first occurence of the "search" word in each tiddler tagged "x" is replaced by a button containing the "replace" word. Clicking the button will eplace the "search" word with the "replace" word.

Downside: You cannot replace selectively. You can only replace from the start of the text to the end, not skipping any occurence.

Reply all
Reply to author
Forward
0 new messages