In Writer: go and select until xxx

I work in Writer 7.542 (X86_64) on Windows 11 64 bits. I know that when my cursor stands somewhere in a text, the command Ctrl+Shift+End blocks everything from cursor position to the end of the document. But is it also possible to block from the cursor position until a certain string of characters, such as @@@ Thanks in advance!

I am not aware of such a function.

Workarounds:

  1. menu Edit > Search
  2. click in the status bar (View > Status Bar) at page x of y, choose a page number in the dialog and OK.
  3. go to the navigator in the sidebar and double click on an item to get there.

Via macro.
And you can assign the keyboard shortcut for the macro in menu Tools > Customize.

Sub selectToChars 'selection from view cursor to some characters
	const cChar="@@@" 'characters, end of selection
	dim oDoc as object, oVCur as object, oDesc as object, oFound as object
	oDoc=ThisComponent
	oVCur=oDoc.CurrentController.ViewCursor 'visible cursor
	oDesc=oDoc.createSearchDescriptor
	with oDesc
		.SearchString=cChar
		'.SearchRegularExpression=true 'by regexp
	end with
	oFound=oDoc.findNext(oVCur.End, oDesc)
	if NOT isNull(oFound) then oVCur.goToRange(oFound.Start, true) 'or oVCur.End to select with cChar
End Sub

Thanks a lot, I will try that out!

I have tried it out and it works very well, the macro does what I wanted it to do, and I added the Run Macro command to my standard toolbar using Tools > Customise.
In order to be able to run this macro repeatedly (extending the selected block with each run) I must manually move the cursor to after the used string (@@@); if you can indicate how I can change the macro so that the cursor lands after that string, I would still be more grateful than I already am now!

Use the extension MRI or XRay → for example mri oVCur or xray oVCur to show the properties or methods of some variable (or simple Basic method msgbox oVCur.dbg_methods or msgbox oVCur.dbg_properties.
If I understand well, you need start new finding from the end of previous one:

	oVCur=oDoc.CurrentController.ViewCursor 'visible cursor
	oVCur.collapseToEnd() 'set cursor to the end of selection

I don’t want to cause you more trouble than I have already done, but ideally I would want my macro to block from the cursor position until after the string in question (let it be @@@, but a more realistic example would be to have it search the string http in a collection of clippings from the Internet) and to extend that block – on my command-- until after the next occurrence of that string, and that as often as I want

You don’t trouble me, I really like these small IQ tests with macros :slight_smile:
I suppose you don’t want to include @@@ to the selection, so here is “double searching” for @@@.

Sub extendToChars 'extend selection from end of view cursor to some characters
	const cChar="@@@" 'limit
	dim oDoc as object, oVCur as object, oDesc as object, oFound as object
	oDoc=ThisComponent
	oVCur=oDoc.CurrentController.ViewCursor 'visible cursor
	oDesc=oDoc.createSearchDescriptor
	with oDesc
		.SearchString=cChar
		'.SearchRegularExpression=true 'by regexp
	end with
	oFound=oDoc.findNext(oVCur.End, oDesc)
	if NOT isNull(oFound) then 'limit is found
		if oDoc.Text.compareRegionStarts(oFound.Start, oVCur.End)=0 then 'end of cursor = start of limit (typical situation from previous extending)
			oFound=oDoc.findNext(oFound.End, oDesc) 'find next limit
			if NOT isNull(oFound) then oVCur.goToRange(oFound.Start, true) 'limit is found, extend to new limit
		else 'end of cursor isn't at start of limit, extend to limit
			oVCur.goToRange(oFound.Start, true)
		end if
	end if
End Sub

Many thanks: it works perfectly! I also succeeded in assigning this macro to a keyboard shortcut, so I can go on extending a selection in a Writer document by pressing that keyboard combination as often as I want (more or less like F8 does in MS Word). Beautiful and very practical! I tried to find where I could drop a suggestion to have it included in the program, but I can’t seem to find it. Anyhow, thanks again!

You can write suggestion to Bugzilla.

I would suggest to use a bookmark for the target you want o “select until”.
The attached example demonstrates how to do so, and it comes with an extraToolbar to call the needed macro. The toolbar may first be shown somehow displaced, but you can easily drag it to an appropriate place.
This is not yet included, but you can use the three modifyer keys (Shift, Ctrl, AltLeft) to get up to 8 =2^3) variants for a single sensitive toolbar area (using different bookmarks e.g. in our case).
disask94607selectFromCurrentPositionTillBookmark.odt (61.4 KB)

[Always check document macros for the absence of malign code before permitting execution.]

I will have to study this, but many thanks anyway!