Can anyone think of a way to create a text selection that begins and ends with the word* that is "under" the I-Beam.
tl;dr:
Mirror VIM's "Select Inner" motion (via the concept of "Text Objects") to create a text selection.
- https://everythingsysadmin.com/2010/09/a-powerful-vim-command-i-never.html
- http://vimdoc.sourceforge.net/htmldoc/motion.html#iw
- https://stackoverflow.com/a/14233556
- https://blog.carbonfive.com/vim-text-objects-the-definitive-guide/
(*Not necessary a single word, but at least, the characters between a start
and end
space
character.)
Text Objects and Motions in VIM:
Why?:
I already have a macro which takes the currently selected URL (in say, a text file), copies it and is passed to the Open URL
KM action.
I was trying to feed my laziness* by having Keyboard Maestro automatically recognize the start/end of the URL (that surrounds the I-Beam
) for me and create the selection between those points.
(*With the tacit acknowledgment that I will likely spend more time investigating how to accomplish this than I will save.)
As a result, the I-Beam could be anywhere within the URL string, and I could go to
that URL with a single keystroke trigger.
I can imagine this type of functionality being useful for any macro that relies on grabbing some text before Keyboard Maestro does some work on it.
Also: I've been getting into VIM and this is a fundamental (and brilliant) motion.
What I've tried:
-
I experimented with
control-right/left arrow keys
. Which could conceivably work with single words. But it won't work with a complex URL.- ex: Ones with query strings like:
- https://forum.keyboardmaestro.com/search?q=vim+text+objects
-
I looked into various RegEx ideas (matching URLs, using word boundaries, etc.). But I don't think any of those will work, because to use them in KM, you have to first feed it some text via a selection & copy. And what I'm looking to do is the step just before that. Essentially
Step 0
. -
I searched the forum and couldn't find anything similar.
-
In Sublime Text 3,
command-d
(select word) andcommand-shift-space
(select words enclosed in quotes) basically do it:- https://stackoverflow.com/a/11712061
-
command-shift-space
seems to do a great job with URLs! - But this only works in Sublime Text 3. Not, for example, TextEdit.
- Maybe since ST3 is able to accomplish this, it's a good indication that Keyboard Maestro would be able to as well?
Misc:
-
VIM allows you to go further and specific the "boundary" characters. It would be good to be able to select boundary characters other than a
space
. But it's not completely necessary to be able to do that in real-time via KM. A macro with predefined boundary characters would be fine. -
I can imagine this being something Keyboard Maestro could handle (either it already can or as a feature request). But I could be wrong.
-
If anyone knows of a standalone utility that mirrors VIM commands like this, or something built into the OS that does this, I'd love to know about it.
-
Sublime Text and other text editors have VIM modes or plugins that seem like they might be able to accomplish this (like what I found above). But then it would only work in those editors. Not terrible, but it would be best if it was system wide.
-
Implementation idea: Move cursor to
X character
- I know @peternlewis likes Keyboard Maestro's actions to be fundamental (so they combine well with others and don't overlap), so a
select inner word
action is probably too specific. - Maybe the following is better:
-
Move cursor to closest next \s
(using RegEx "space" meta-character) -
Move cursor to closest previous \s
(using RegEx "space" meta-character)
-
- Or even simpler:
Move cursor
+closest next/previous
tokens ?? - But I'm probably getting ahead of myself. I wouldn't be surprised if either of these is outside of the scope of KM. It was just a thought.
- I know @peternlewis likes Keyboard Maestro's actions to be fundamental (so they combine well with others and don't overlap), so a
Thanks!