Internet Search Macro covers this topic. Using its info I made two macros that I think do what you’re looking for — one for Google and one for DuckDuckGo.
Also I’ll attach a couple other useful macros on this subject that may be of help.
(FYI, MacOS has what you’re looking for built into it too. I will put details in a comment section of the macros.)
Search DuckDuckGo w: Selected Text.kmmacros (3.9 KB)
Search Google w: Selected Text.kmmacros (3.9 KB)
Search The Web - DDG.kmmacros (1.6 KB)
Search The Web - Google.kmmacros (1.6 KB)