128

I'm migrating from Eclipse to Intellij Idea. One thing I couldn't figure out yet is autocompletion of the @author JavaDoc tag. When typing @a in Eclipse, there are two proposals:

@author - author name
@author

How do I achieve the first proposal in Intellij (is it even possible?)? And if it's possible, how do I change the template of what is inserted for the author name placeholder?

2
  • stackoverflow.com/a/34475894/907576 there I propose to vote up Jetbrains bug-tracker issue "Configure custom author name/email/organization to be used in file templates, completion etc"
    – radistao
    Commented Dec 26, 2015 at 22:42
  • In IDEA 16.3 (at least) it works exactly as you ask. Commented Dec 22, 2016 at 12:34

6 Answers 6

293

One more option, not exactly what you asked, but can be useful:

Go to Settings -> Editor -> File and code templates -> Includes tab (on the right). There is a template header for the new files, you can use the username here:

/**
 * @author myname
 */

For system username use:

/**
 * @author ${USER}
 */

Screen shot from Intellij 2016.02

2
  • 9
    IDEA 15 : File > Settings > your steps. Commented May 4, 2016 at 19:01
  • 1
    How can add the current date as well? Commented Oct 30, 2019 at 12:52
107

You can work around that via a Live Template.

Go to Settings -> Editor -> Live Templates, click the Plus Icon Button (on the right).

In the "Abbreviation" field, enter the string that should activate the template (e.g. @a), and in the "Template Text" area enter the string to complete (e.g. @author - My Name). Set the "Applicable context" to Java (Comments only maybe) and set a key to complete (on the right).

I tested it and it works fine, however IntelliJ seems to prefer the inbuild templates, so "@a + Tab" only completes "author". Setting the completion key to Space worked however.

To change the user name that is automatically inserted via the File Templates (when creating a class for example), can be changed by adding

-Duser.name=Your name

to the idea.exe.vmoptions or idea64.exe.vmoptions (depending on your version) in the IntelliJ/bin directory.

enter image description here

Restart IntelliJ

0
30

Check Enable Live Templates and leave the cursor at the position desired and click Apply then OK

enter image description here

15

For Intellij IDEA Community 2019.1 you will need to follow these steps :

File -> New -> Edit File Templates.. -> Class -> /* Created by ${USER} on ${DATE} */

enter image description here

3
  • How to specify Date format in the template?
    – nanosoft
    Commented Mar 4, 2021 at 6:31
  • 1
    There is no direct way to format date so instead of ${DATE} you can use ${YEAR}-${MONTH}-${DAY} Commented Mar 7, 2021 at 13:31
  • @nanosoft The comment from @Suditi didn't work in intellij 2022.1. I had to create a template variable named $today$ and assign it the function date("YY-MM-dd").
    – cb4
    Commented Aug 11, 2022 at 17:45
5

Just to answer some of the questions here:

Yo can also add predefined variables that take the following values:

${PACKAGE_NAME}      Name of the package in which the new file is created
${USER}              Current user system login name
${DATE}              Current system date
${TIME}              Current system time
${YEAR}              Current year
${MONTH}             Current month
${MONTH_NAME_SHORT}  First 3 letters of the current month name. Example: Jan, Feb, etc.
${MONTH_NAME_FULL}   Full name of the current month. Example: January, February, etc.
${DAY}               Current day of the month
${DAY_NAME_SHORT}    First 3 letters of the current day name. Example: Mon, Tue, etc.
${DAY_NAME_FULL}     Full name of the current day. Example: Monday, Tuesday, etc.
${HOUR}              Current hour
${MINUTE}            Current minute
${PROJECT_NAME}      Name of the current project
1

If in File -> New -> Edit File Templates no type of files which you want, or you want to annotate the edited file, like

/**
 * Updated by USER.
 * Date: 06.04.2023
 * Time: 9:11
 */ 

You can go to Settings -> Editor -> Live Templates create a template with variables

/**
 * Updated by $user$.
 * Date: $date$
 * Time: $time$
 */ 

and on the right click button Edit Variables... and set these variables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.