An example of a plugin that would do something like this is the following bit of code. You can use Tools > Developer > New Plugin...
and replace the stub that’s generated with this, then save in the location that Sublime will default to, which is in your User
package. The name is unimportant as long as it’s got a py
extension, but you may want to name it something that lets you know what it’s doing. 
import sublime
import sublime_plugin
import os
import re
# A regular expression that matches the start of a note. It's best
# that this either be something unique that won't appear in notes or,
# better still, anchored to the beginning of a line such as in the
# example text.
_note_prefix = r"^- "
class SplitNotesCommand(sublime_plugin.TextCommand):
"""
Given a file with a name, try to find all of the notes using the
above _note_prefix and write them out to files with names based on
the name of the current file.
When dry_run is True, the regions that are considered notes are
outlined to allow you to verify that things are being found
correctly.
"""
def run(self, edit, dry_run=True):
# Obtain a list of regions that match the note prefix. This
# tells us where all of the notes in this file start.
notes = self.view.find_all(_note_prefix)
# Now we can iterate over all of the note prefix regions and
# create a list that expands them to the whole note. We'll say
# that a note begins right after the prefix and runs right up
# to the start of the next prefix that appears in the file. In
# the case of the last note, we instead end at the end of the
# file instead.
eof = sublime.Region(len(self.view))
note_regions = []
for idx, note in enumerate(notes):
end = notes[idx + 1] if idx + 1 < len(notes) else eof
note_regions.append(sublime.Region(note.b, end.a))
# If this is just a dry run, mark the file to show where the
# notes would be split, and then leave.
if dry_run:
self.view.add_regions("notes", note_regions, "comment",
flags=sublime.DRAW_NO_FILL)
return
# Split the filename in half at the extension.
base_name, ext = os.path.splitext(self.view.file_name())
for idx, note in enumerate(note_regions):
# Create a file name to be used for this note, which will
# be based on the name of the current file with a numeric
# prefix attached.
note_name = "%s_%03d%s" % (base_name, idx + 1, ext)
# Grab the contents of the file that spans the note region
note_text = self.view.substr(note)
# Write it to disk now. This doesn't error check, for
# brevity. It's also not checking that it might clobber
# over an existing file.
with open(note_name, "w", encoding=self.view.encoding()) as file:
file.write(note_text)
# Display the count.
sublime.message_dialog("Generated %d notes" % len(note_regions))
def is_enabled(self):
# Only enabled for files that have been saved
return self.view.file_name() is not None
The code is commented to give you an idea of how it’s working, but basically it looks through the file for a regular expression that matches a note prefix, and then everything between prefixes (but not including the prefix itself) is considered to be a single note.
From there it can grab the text out of the file and write it out to a new file. The name chosen is based on the name and location of the file that you run the command in, with a numeric suffix added to the end, so for example sample.txt
becomes sample_001.txt
and so on.
This doesn’t check that files with those names don’t already exist, nor does it check if there’s an error writing to disk. Presumably as long as you have permission to create files in the location where the source is, and you safely name your source file, that’s not too much of a problem.
For safety if you run the command without any arguments it will mark the regions in the file that are considered to be notes without actually generating any files. That way you know for sure that it’s going to do what you expect before it starts dumping tons of files everywhere. You probably want to also put your source file in an empty folder to control where the output goes as well.
To use it, open the file with the source notes and use View > Show Console
. While the notes file has the focus use one of the following lines to run the command; the first one runs the command in “safe” mode, just showing you what it would do, and the second one actually generates the files, once you’re sure it’s working.
view.run_command("split_notes")
view.run_command("split_notes", {"dry_run": False})