Search code examples
eclipseeclipse-cdt

Add parentheses around C-expression in Eclipse


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.


Solution

  • 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.