I have tried searching Obsidian and reddit forum, as thought one of the hotkey plugins might have what I am looking for, but no success yet.
What I’m trying to do
I am documenting some MATLAB code using codeblocks (```) for script, with images and further explanation between each block.
The ‘Editor Syntax Highlight’ plugin, supports Octave highlighting in edit mode, but sadly not in display view. The built-in syntax highlighting is the opposite showing highlighting using ```matlab in display view but not edit mode. Neither of them are amazing (presumably due to MATLAB being less open / popular than python etc), but it is still fairly helpful so a workaround would be working with ```octave and then replacing all blocks to ```matlab at the end.
Question: Is there a way I can create a custom command or key shortcut to find and replace all occurences of a particular word. In my case, a command that replaces ```octave with ```matlab for all occurences in the file?
I imagine this is possible with a Templater script, which lets you execute arbitrary Javascript in the app. Something like: get the note text, replace oldString in note text with newString, write new note text to the note.
Use the Hotkeys for Templates plugin to bind such a template to a keyboard shortcut.
In the meantime, Obsidian does have a conventional find-and-replace feature.
I will also need to delete existing content before replacing with updated, but couldn’t even get this first step working. Console returns: Template parsing error, aborting. missing ) after argument list
If anyone here can assist that would be appreciated! Thanks!
You’re actually pretty close, but you still need to use Obsidian API functions to manipulate the contents of the doc—return won’t do it because Templater doesn’t actually do anything with the returned output.
I don’t have the time to edit your code right this second, but I’ve done something similar with this. You might be able to use what’s in there to fix what you’ve done already.
This did originally give the notice when I ran it originally yesterday. However now I receive the same error: Template parsing error, aborting. missing ) after argument list
So turns out I have a more fundamental issue to deal with first. I have setup Templates folder and TemplaterJS folder, with the .js files matching correct code.
Having searched about a few others have experienced this due to not have filenames correct / folders setup, but I can’t get it working.