1

Is there a way to select a C/C++ expression in Eclipse and put a bracket around it with a single keyboard shortcut? IDEs usually have this but I couldn't find a way in Eclipse.

For Java Code, there is a more or less good workaround described in Parentheses over selected words in Eclipse, but this does not work for C-Code - after bringing up the template list for the selection, the suggested templates are empty.

Jens
  • 6,173
  • 2
  • 24
  • 43
  • Shift+Alt+Z shows all templates that contain `${line_selection}`, so you can make the template `(${line_selection})${cursor}` to select something and hit Shift+Alt+Z. Unfortunately, this does not work for multi-line selections because everything in the template in the line before `${line_selection}` will be applied to each selected line. – howlger Nov 13 '18 at 17:09
  • That's what I'm looking for! Would it now additionally be possible to assign a shortcut key to this? I'm accustomed from other IDEs to press "SHIFT+(" and if a word is selected, the Editor puts the brackets in. Like pressing "/" on a selected line and it gets commented out! BTW. could you make this an answer so that I can mark the issue as solved? – Jens Nov 14 '18 at 09:32

1 Answers1

2

As far as I know, exactly that is not possible. You might report it to Eclipse CDT as a feature request.

But as workaround a template like the following can be used:

(${line_selection})${cursor}

If you hit Shift+Alt+Z the Surround With Quick Menu shows all templates containing ${line_selection} and with a number key a templated can be selected.

The key Shift+Alt+Z can be changed, but unfortunately no key can be defined to select the template directly. Also unfortunately, this does not work for multi-line selections because everything in the template in the line before ${line_selection} will be applied to each selected line.

howlger
  • 31,050
  • 11
  • 59
  • 99