Custom ${user} with C/C++ Code Templates

The Eclipse Editor has a very cool feature named ‘Code Templates’: With such templates files are created with specific pre-filled content. For the templates, variables like ${user} for the user name can be used, see Custom C/C++ Headers with Eclipse:

Eclipse Code Template Editor

As for the variables like ${date} or ${user}, they defined by the system on which Eclipse is running. For for ${user} it uses the user name I have used for the login. But that might not be what I want to have used for example in the header or source file.

The question is: how to change the content of the ${user} variable? For example I want to show my full name and not my login name:

Showing full user name

Because it is derived from the system, it does not make sense to have a setting for it. But there is a trick to change it for Eclipse :-).

For this, locate the Eclipse startup .ini file. For example for the NXP MCUXpresso IDE, it is located in the same folder as the executable and named mcuxpressoide.ini.

Open that file with a text editor and then set the variable user.name with the desired name:

Restart Eclipse, and now it will use that custom value for ${user}.

Custom User Name for Code Templates

Happy templating 🙂

Links

4 thoughts on “Custom ${user} with C/C++ Code Templates

      • There are 5 direct references to the “user.name” property in the CDT sources. Most of these are used for logging or presentation only. However, this property will be used to pre-populate the “User” field in the Launch Terminal dialog for SSH terminals. Dereferencing of the “${user}” token is performed by a template variable resolver within JFace code that is common to many Eclipse/RCP products. We simply cannot predict how other plugins may choose to use these system properties and whether they rely on their documented default values.

        Liked by 1 person

        • Hi John,
          OK, I see your point. And indeed, this could be problematic. Do you know any other way to change the code template variables or creating a new one? Sure one could write his own plugin, but that’s not ideal.

          Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.