问题
Hopefully a nice quick one for someone. I'm working on a project that requires a specific link being written around 400 or so locations. Each link is the same, except it has the town's name in it, such as:
<li><a href="/contact-details.html?location=Andover">Andover</a></li>
I'm currently using Komodo Edit to write my projects, and I have Zen Coding installed and a decent knowledge of the built-in Snippets functionality.
I know that using Snippets, I could create the link above from the word Andover in a key-binding, but as far as I know only one line at a time.
I also know that I could use Zen Coding to get to the stage of:
<li><a href="/contact-details.html?location=">Andover</a></li>
but without the location name in the link by using wrap with abbreviation and
li*>a[href=/contact-details.html?location=]
Obviously both of these still leave quite a lot of work to do, and I'm sure it's possible with a Komodo macro but I don't know enough about them to do that.
Does anyone know of a way in Komodo, or using Zen Coding, or any website or application, that can do this kind of slightly more advanced find/replace / text-expansion? I've seen a few applications that do find and replace but they all base themselves around multiple files and that's a bit much for what I need.
Ideally, so I can write things like
<li><a href="/contact-details.html?location=[%contentOfCurrentLine]">[%contentOfCurrentLine]</a></li>
and replicate it over all 400 locations in one go.
回答1:
Use a snippet like this named 'ListLink':
<li><a href="/contact-details.html?location=[[%W]]">[[%W]]</a></li>
And create a macro using the scimoz and projects APIs to move the cursor and call the snippet in a loop:
komodo.assertMacroVersion(2);
if (komodo.view && komodo.view.scintilla) { komodo.view.scintilla.focus(); }
var i = 1;
var len = ko.views.manager.currentView.scimoz.lineCount; /* Count lines */
_part = ko.projects.findPart('snippet', 'ListLink', '*'); /* Find Snippet*/
ko.views.manager.currentView.scimoz.documentStart(); /* goto first line */
while (i <= len)
{
if (!_part) {alert("Couldn't find a snippet called 'ListLink' when executing macro."); return;}
ko.projects.invokePart(_part); /* invoke Snippet */
ko.views.manager.currentView.scimoz.lineDown(); /* goto next line */
i++;
}
回答2:
You can do that in Komode.
- Go to "Edit" ( in top menu), "Find".
- Will open a window, check the chackbox "Replace" (or others that you need)
- Complete the text fields "find what" and "replace with", them click "Replace All"
Just it!
来源:https://stackoverflow.com/questions/3905759/advanced-find-replace-text-expand-macros