Hey all, long time user, first time caller here. I'm trying to do a thing that I feel must be possible with KM but can't wrap my brain around how.
Background: I use Obsidian as well as The Archive for dealing with markdown files. As a result, I have a lot of things in various places that are links using timestamp based uids, that look like this:
There's a bunch of things that would be a lot easier if I could figure out how to grab out just the numbers from between those brackets and put them into a variable.
I can guarantee the string will always be the same length, 12 digits
I can guarantee the surrounding string will always be double square brackets
I cannot guarantee where in a line this occurs; they are scattered liberally throughout documents.
Here's the hard part: I would like to be able to do this from any cursor position within the digits. I have a solution for if I'm before the first two brackets (lots of emulated arrow keys), But I would like to be moving my cursor around through the text with my keyboard, find myself in the middle of one of these links, and extract the useful info from it.
Here’s one way of doing it. Basically (assuming your cursor is inside the brackets), it positions the cursor behind the brackets, then selects the brackets, then extracts the digits only, displaying them in a window.
Try it out and see if it works for you. If it doesn’t for some reason, let me know and we can go from there.
Thank you! This... works, mostly? In that it does in fact extract the digits and display them, but after the fact the selection in the document is expanded out to include the words on either side (and if it's at the beginning of a line, all the blank lines between it and the word in the previous paragraph). So, it works, but I'm a little concerned about the selection after the fact being potentially dangerous if I'm moving too quickly. I tried dropping in an ESC after and that kind of works, but it's not going to play well with, say, vim.
Update: The above is the behavior in The Archive. When I try to implement this in obsidian thusly:
for some reason the search results are set to the number plus the brackets, but if I then do a regular paste, get just the digits (this is likely an obsidian issue and outside the scope the the question, so I don't expect you to fix this bit, I just thought you should know, or if it was something obvious in KM that I'm missing). And also the entire document is selected.
I’m not quite sure I follow what you mean... anything beyond getting the digits is outside the scope of my demo macro. But obviously you could just add a simple simulate keystroke action at the end of the macro, and simulate the right arrow to move to the end of the currently selected text.
Also, you mentioned vim... are you talking about vim on the command line?
I sometimes use vim on the command line, sometimes in a gui, so I'd like the option of being able to expand this for use there. But the most immediate use is in obsidian, where I want to be able to search for the UIDs (without getting into too much detail: The Archive does "linking" as just a search for the string in all files, which gets you everything that mentions that file as well, I want to emulate this behavior in obsidian).
And, of course, emulating a right arrow would work, this is what I get for responding before coffee. Thanks!