How to Select Some Text in RStudio

Say the cursor is placed just after 'group_by(feed)' in RStudio (as in top screenshot). There could be any number of lines of text and the cursor could be anywhere within the text.

Using a keyboard shortcut, is there a way to to select the text from 'chickwts' to the cursor, as in bottom screenshot?

Haven't tested, but it may work:
Simulate:
Shift+ArrowUp
Shift+ArrowUp
Shift+Arrow Right

Thanks it does work but only if there are 3 lines of text. There could be any number of lines of text. Sorry -I should have said this. I have edited the question.

Hey Ross,

I would try two things.

  1. See what Ctrl-A does. This should take you to the beginning of the paragraph, but you'll have to test to see what RStudio considers a paragraph in that situation – and whether it supports the macOS EMACS keyboard shortcuts.

  2. I'd see if the Set Find Pasteboard action works with RStudio. If it does you might be able to get fancy using some regex.

-Chris

The difficulty is telling KM when to stop.
I saw that in your cases, both the beginning of the selection have a blank line before it and both the lines do not have any indentations (space or tab).
I made this macro based on these two characteristics. Hope it works for you in most cases.

Select Lines Above Until Reach End of Line & Next Not Beginning with Space or Tab.kmmacros (5.9 KB)

image

1 Like

That works nicely thanks.

1 Like

First, please post a screenshot of only the region of interest on your screen -- not the entire screen.
When you post the entire screen the details are hard to read.

So let's look at the region of interest:

image

Unfortunately, I don't know of any way to select text based on the actual text involved, in this case "chickwts", UNLESS the app supports AppleScript that can access the text and characters in the window.

From a quick search, it appears that RStudio no longer supports AppleScript . You can double-check by viewing the Scripting Dictionary in Script Editor (menu file > open dictionary), and look for RStudio.

There are macOS shortcuts to select to end/start of line, and end/start of paragraph, where a paragraph is delimited by CR or LF.

The only idea I have involves some manual interaction.
You could have KM ask how many lines up to select, and then do something like this:

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Select Lines in App [Example]

-~~~ VER: 1.0    2021-03-08 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Select Lines in App [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


Many thanks that is another useful way of doing it.