How to Move a Sentence in a Text?

I would like KM to move the sentence where the cursor is to a new paragraph above or below.

Example

From this

"This is a sentence. This is the sentence to be moved. And this is another sentence."

Make this

"This is a sentence. And this is another sentence.

This is the sentence to be moved."

Moving paragraphs is a standard feature of many text apps. (Eg Apple Notes, ⌘⌃+ up/down arrow). I'd like this for sentences.

So KM would have to recognize text between different punctuation marks. (. ? !)

Thanks for your help!

You would have to specify one or more particular applications, I'm afraid.

(There's no universally standardised macOS UI or API across different applications for text selections or text cursor positions)

Mm, ok, thanks.

If I want to highlight a word, I can do that with a double click.

Do you know a way to highlight a whole sentence? (Text that is between . ! ?). That would solve the problem. :slightly_smiling_face:

There are a few methods, including shortcuts, to select words, lines and paragraphs, but I don't know of one to select a sentence.

Shuffling sentences is probably doable via RegEx if the group of sentences is pre-selected though.

I have not found anything either. :slightly_frowning_face:

I have no idea about RegEx, but that is supposed to be very powerful.

Can't you use it to highlight text that is to the left and right of cursor up to the next punctuation mark?

No, but you can use it to process the text once you get it into KM.

https://wiki.keyboardmaestro.com/Regular_Expressions

I see. But if I have to highlight the sentence manually, I've already done everything. The rest is simple.

What is easy is to jump from period to period with the search function. Now you would only have to find a way to highlight the text in between :joy:

Anyway, thanks @noisneil

Even though you have not responded to @ComplexPoint’s question about which app you’re working in, you say it has a search facility so the question now is: does that search facility support regular expressions?

Ah, sorry, I didn't understand the question. As far as I know yes. I want to do this (mainly) with Scrivener.

Now that you mention it, someone on the Scrivener forum pointed it out. But I have no idea how to apply it. A KM macro would be ideal.

This reply of mine is unlikely to give you what you’re looking for but here goes anyway.

For “fun” I created a regex to do what you asked in your original post. You can see it in action here regex101: build, test, and debug regex - take a look… The problem with this regex is that it’s tailored specifically to your example so that it would likely not work if the text you gave it was different.

In my view to employ this in Scrivener’s search/replace dialog would take more time and effort than simply getting in there and moving the sentence manually. It may be that you could get a KM macro to “drive” the search/replace dialog but I can’t explore that option for you right now.

Have you tried asking the question in L&L’s forum?

Thanks @tiffle I will try this out right away.

In the meantime, I had another idea that works manually and might be transported into a KM macro. But I do not know how.

  • With the search function I jump to the period of the preceding sentence.

  • Now the cursor is at the beginning of the sentence I want to highlight.

  • ⌥⇧+right arrow highlight each word individually.

Can KM repeat this (slowly) until I cancel (this action)? Then cut out this text (Clipboard)?

I can envision a way this could work, but only if the punctuation is consistent, unless you can search for one of multiple matches.

Somehow like this :joy:, but of course not 4 times, but until I break off (eg with space)

What do you mean?

And of course I appreciate your help very much :grinning:

If that helps. This is the search box. I'm looking for the last (.) ("Vorherig"). That works fine.

What if the previous sentence ends with a question mark?

I would already be satisfied with (.). This is the most common case.

I could also live with having (3) macros for . ! ?
Finally I see how the previous sentence ends.

Why bother when Scrivener already has a “select sentence” facility?

From the Scrivener manual (p. 716):

Select ▸ Select Sentence As noted above, if you start with two partially selected
sentences then you would end up with two fully selected sentences when
using the Select Sentence command. Given the wide range of languages,
writing styles and methods, right, wrong or just creative—grammatical
constructs such as sentences can only be estimated.

And you can assign a keyboard shortcut to it using the usual MacOS procedure.

Of course there’s also the “move” facility built-in to Scrivener…

4 Likes

This is really embarrassing. :cold_face:

I have been working with Scrivener for many years and have never noticed this feature. I will test this more closely in a moment.

Thanks a lot @tiffle and @noisneil and sorry for bothering you for nothing :man_shrugging:

edit // My ignorance is a direct result of using apps like KM, so to speak. You don't look at the menus anymore. :innocent:

I always look through the menus of my apps when they're new – and periodically do so with old ones...

I regularly use the search field in the Help menu of apps to look for things.

I also use KeyCue to display a searchable map of menu items (and KM macros).

A free alternative to KeyCue is CheatSheet.

Knowing the capabilities of your tools gives you many more options with Keyboard Maestro...

:sunglasses:

1 Like

Thanks Chris, I'm sure you're right. :grinning:

However, in this case, I was trying to solve a problem with KM that the app had already solved. :joy:

In my defense, I can say that this feature is very unusual. I don't know of any other app that can do this.

Selecting word, line, and paragraph are common functions in many editors (particularly programming editors), however Scrivener is the only app I've ever seen to add “Select Sentence” to that group.

Pretty slick.

Too bad Scrivener is not at all scriptable...