0

I use Sublime Text often for non-coding writing, where the ability to select/highlight text from a cursor position to a search term can be handy. Is this possible with the built-in shortcuts?

To give an example, let's say I have the following text:

Be patient till the last. Romans, countrymen, and lovers! hear me for my cause, and be silent, that you may hear: believe me for mine honour, and have respect to mine honour, that you may believe: censure me in your wisdom, and awake your senses, that you may the better judge.

My cursor is under the 'p' of 'patient', and I want to select text from there to 'lovers!' In Vim, I could do v/lovers!, and it would expand selection from 'patient' to 'lovers'. Vi-mode in Sublime Text can't do that (and I wouldn't expect it to) ... but can Sublime Text do something like this natively?

1 Answer 1

1

I’m not sure what the norms are for answering one’s own question here, but since I got the dreaded Tumbleweed badge for this one, I figured I’d try to do it myself.

Here’s a (very inelegant) approach I came up with; only works in ST3. The basic idea is that you initiate an incremental search (or regular Find, and exit the search field with ESC), set a mark, rewind to the prior cursor position, extend selection to mark, then clear the mark. This can all be encapsulated in the following macro , then assigned to a shortcut key:

[
{
"args": null,
"command": "set_mark"
},
{
"args": null,
"command": "jump_back"
},
{
"args": null,
"command": "select_to_mark"
},
{   "args":
    {
        "name": "mark"
    },
"command": "clear_bookmarks"
}
]

It boils down to: 1) run incremental search (command-I in OS X, exits search field on enter), 2) hit shortcut key.

Two big caveats. 1) This only works in ST3, because ST2 doesn’t have a built-in function for returning to previous cursor position. 2) It will delete all the marks, so if you regularly use marks, you won't like this macro (though I’m sure it can be adjusted to just delete the last mark).

It's no v/<search term>. It’s an ugly workaround. But it works, at least for ST3. If anyone knows a more elegant way of doing this, or how to do it in ST2, please share.

1
  • Although it's nine years later, and I'm looking for a solution for NotePad++ (which does not support "find and extended selection"), I gave you a +1 for taking the time to pose the question and answer it with the best solution you could think of. Commented May 31, 2023 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .