The settings will work anywhere; the “issue” (and whether or not it really is an issue is up to interpretation) is that in order to use them, the thing that is the link needs to be the name of the file. That is to say, you can make chapter_two.txt
a link, or book/chapter_two.txt
a link, but you can’t make it arbitrary text like chapter two
without some sophisticated plugin magic.
If that’s not a problem, then it’s pretty easy to get them doing what you want with no plugin code at all, and you can take it to varying degrees as well.
I’ll also preface this by saying that there are quite likely packages that are available that will allow you to follow links in files. I don’t use any personally and they may or may not be entirely the province of jumping between source files and not plain text though, I’m not sure.
Here’s a simple thing you can do right now; open a text file and use Preferences > Settings - Syntax Specific
to open the settings file for plain text, then add these settings:
"result_base_dir": "/home/dutch/writing/book/",
"result_file_regex": "(\\w+\\.txt)()()()"
The result_file_regex
is used to match text represents some file that can be navigated to. The regex is expected to have 4 capture groups (the ()
bits) that capture from the matched text, in order, the file name, the line in the file, the column in the file, and an error message/info text/etc.
The only group that’s important is the one that captures the filename, since that is how Sublime knows where to go; the other information can be used to open the file on a specific line or to a specific line and column as well.
The result_base_dir
setting is used to determine where files that result_file_regex
matches live, if it’s not an absolute, fully qualified filename.
With these in place, any .txt
file with something that appears to be a text file name (e.g. chapter_two.txt
) will make that filename something that will open the file; you can double click on it and the file will open (or a tab is created if the file doesn’t exist; possibly handy way to generate new chapter files since you can type and save into them directly).
As written here, the regex is very simple; you could make it more complex to allow things like path parts as a part of the matched text, etc. The thing to keep in mind is that whatever matches will be double clickable, even if it accidentally matches something that’s not an actual filename.
You’ll notice that although you can double click the filename to open it, there’s no indication that such is actually possible. With a bit of extra tweaking, you can make that more obvious (and if you use ST4, you can take it to an extra level, see below).
I’m mentioning this here because I know from past question you’ve asked that you were working your own custom syntax for your prose, so this might also appeal for that reason.
Imagine a syntax definition that looks like this:
%YAML 1.2
---
# See http://www.sublimetext.com/docs/syntax.html
scope: text.plain.prose
contexts:
main:
- match: '\w+\.txt'
scope: markup.underline.link
This is a very small constrained example, but the takeaway here is that there is a match rule that matches the same pattern for filenames as the setting is using, and it applies a specific scope that scopes the text as an underlined markup link.
Good color schemes should have a predefined rule for that scope to make links more visible. If you apply this syntax to a file, anything that appears to be a filename will be visibly called out, pointing out that you can double click them (remember that if you do this, you need to re-apply the settings, as they’re syntax specific and now the syntax is different).
For the specific case of ST4, along with the font styles of bold
and italic
that ST3 supports, you can also apply font styles for underlines; the following is how the sample here looks in ST4 using the stock Mariana color scheme: