Super-Delete shortcut

Hi, is there any way I could create a keyboard shortcut (like ctl-shift-del) that would delete all instances of whatever was selected in the document?

For instance, say I have a file and I am editing a cell and decide I don’t want a certain phrase like “cats just don’t eat cheese” anywhere in my spreadsheet. Normally I would enter that phrase into find and replace, replacing it with nothing. But if I had a Super-Delete shortcut, it would automatically find all instances of the phrase and replace it with nothing. So basically the Super-Delete shortcut would find and replace the highlighted phrase, finding all and replacing it with nothing.

It would save me the trouble of copy and pasting the text into find and replace in the case where the “replace” text is nothing. I could just select a phrase, hit Super-Delete, and all instances of the phrase would automagically be removed from the document.

Is that possible?

Cheers

Find and Replace: Find All, Replace them with “nothing”.

By theh way, I see that there is a difference between Writer (that copy the selection to the Find field) and Calc (that doesn’t).

Yes. Create a macro doing what you want (read the selection, do Replace All with this); put it into My Macros; assign a shortcut to the macro in the Customize dialog.

1 Like

I got this working, but it isn’t what I am looking for. The macro you suggested seems to only find and replace (with nothing) the specific phrase I selected when I recorded the macro (“Greek phrase followed by”). I was hoping for a Super-Delete shortcut that would delete any string I have selected.

Here’s the macro:



sub test
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "StringName"
args2(0).Value = "λόγων (noun masc. gen. pl.) Greek phrase followed by single English word, ὁ Τυδείδης the;"

dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args2())

rem ----------------------------------------------------------------------
dim args3(20) as new com.sun.star.beans.PropertyValue
args3(0).Name = "SearchItem.StyleFamily"
args3(0).Value = 2
args3(1).Name = "SearchItem.CellType"
args3(1).Value = 0
args3(2).Name = "SearchItem.RowDirection"
args3(2).Value = true
args3(3).Name = "SearchItem.AllTables"
args3(3).Value = false
args3(4).Name = "SearchItem.SearchFiltered"
args3(4).Value = false
args3(5).Name = "SearchItem.Backward"
args3(5).Value = false
args3(6).Name = "SearchItem.Pattern"
args3(6).Value = false
args3(7).Name = "SearchItem.Content"
args3(7).Value = false
args3(8).Name = "SearchItem.AsianOptions"
args3(8).Value = false
args3(9).Name = "SearchItem.AlgorithmType"
args3(9).Value = 1
args3(10).Name = "SearchItem.SearchFlags"
args3(10).Value = 65536
args3(11).Name = "SearchItem.SearchString"
args3(11).Value = "Greek phrase followed"
args3(12).Name = "SearchItem.ReplaceString"
args3(12).Value = ""
args3(13).Name = "SearchItem.Locale"
args3(13).Value = 255
args3(14).Name = "SearchItem.ChangedChars"
args3(14).Value = 2
args3(15).Name = "SearchItem.DeletedChars"
args3(15).Value = 2
args3(16).Name = "SearchItem.InsertedChars"
args3(16).Value = 2
args3(17).Name = "SearchItem.TransliterateFlags"
args3(17).Value = 1073743104
args3(18).Name = "SearchItem.Command"
args3(18).Value = 3
args3(19).Name = "SearchItem.SearchFormatted"
args3(19).Value = false
args3(20).Name = "SearchItem.AlgorithmType2"
args3(20).Value = 2

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args3())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Visible"
args4(0).Value = false

dispatcher.executeDispatch(document, ".uno:SearchResultsDialog", "", 0, args4())


end sub