Plugin to add text to a number of notes

What I’m trying to do

Is there a plugin or a workaround to mark a directory (with a couple of subdirectories and about 100 files) and to add to all files a “footer”. I dont mean to do it with a template and go through all the 100 files. I mean with a click to add something to all files. Is there a workaround for it?

Things I have tried

I searched for plugins but didnt find any.

The only plugin I know that might do it is Global Search And Replace. I don’t know if it has a way to replace “end of file”.

You can probably do it with a fancy text editor like Visual Studio Code or BBEdit that can operate across multiple files. It would also be possible with a shell script if you’re into that sort of thing.

Of course, make sure your backups are up to date before changing many files at once.

1 Like

Actually a template would be the way forward, I think. Using Templater you would have access to javascript which would allow you to loop through the 100 files, and read and modify the content of each file.

Do you know javascript? Or any coding at all?

1 Like

For every template and (it follows) every file, I add a comment by itself in the final line:

%%EoF%%

If I ever need to add anything to all the files or to all the files in a given folder, I use the end-of-file marker for search and replace, usually using VS Code. Not pretty and not perfect but this has helped me a lot, especially adding inline metadata or Dataview queries.

I expect there are better ways to do this.

I now also use a similar start-of-file comment at the top of each file or on the first line under a YAML header (if used).

Huh, I would have guessed VS Code would have a way to do it that wouldn’t need that.

1 Like

Probably, but ‘Simple’ is my middle name. :rofl:

If I’m not mistaken, the sidebar search of VS Code uses RUST regex, and here is a specific reference to empty anchors:

It says that if not in multiline, the anchor $, will match on end of text, aka the end of file. If in multiline, it’ll match on end of line. So there shouldn’t be a need for inserting a dedicated %%EoF%% marker.

Still, if using a plugin like Templater, you’d get the tp.file.content, and anything after that is after the previous end of file. And you wouldn’t then need to use an external tool.

An alternation of this idea to just add a marker is to add something like the following on the first line after the YAML, and on the last line:

`$= await dv.view("js/header") `
... rest of file ...
`$= await dv.view("js/footer") `

This would allow you to change those two specific dv.view() files, and the changes would be seen all across your vault immediately. This way you can update the top and bottom part of your notes any way you feel, whilst keeping the notes to the point on whatever topic they’re about.

I use a setup like this for my daily notes, making it easy to change whenever I feel like it or think of something neat to put into the header/footer sections of my daily notes.

1 Like

Awesome thank for the many replies. Unfortunately I am not into coding. Is there any Tutorial with javascript who already did this kind of stuff? Thank you very much

Thanks. I need to learn how to not be in multiline mode. :thinking:

I don’t at this moment understand your second suggestion, but it is something I will try to fathom out as it sounds ingenious.

Takk :technologist:t3:

  1. If it helps anyone else, this appears to work in VS Code to find the end of files:
$(?![\r\n])

Source: regex - Regular expression to match EOF - Stack Overflow

Not clear if it is the only solution, but …


  1. And rather than using:
%%SoF%%

after a YAML block, I have switched to using a comment inside the YAML block:

# EoYAML

… which means that the files are searchable should I ever need to add a new key and value to multiple YAML blocks.

Leaving this here in case it helps anyone (or to learn if anyone has a better idea).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.