In CLion (e.g. 2021.2), if you type namespace foo
, nothing special happens. I would have liked it if this would get me:
namespace foo {
} // namespace foo
with the cursor on the middle line. How close can I get to making that happen?
Inspired by your answer, and with full credit to you for getting this far, I have progressed this such that the Live Template behaviour you seek is automatically invoked just by typing namespace<space>
.
To set this up, create the Live Template as per that answer, but make sure:
namespace
, as this is used to select this template once expansion is triggered, and$END$
variable, as that sets the final cursor position to be within the new namespace:namespace $NAMESPACE_NAME$ {
$END$
} // namespace $NAMESPACE_NAME$
namespace
keyword to automatically trigger the selection of the template.Now you can type namespace<space>my_namespace
and it will automatically create the following text, as you type, with no need to select from a dropdown or hit Tab, and the cursor will be placed at the start of the blank line within the new namespace:
namespace my_namespace {
} // namespace my_namespace