Search code examples
javaintellij-ideaintellij-plugin

Fast variable insertion into string


Is there any Intellij Idea hotkey or a plugin to quickly insert variable into string? e.g. i have string

"My code is working, yay! Result is = ",

and i have to add construction "+variable +", resulting in

"My code is working, yay! Result is = "+ variable +"."

to properly insert a variable.

When i have to insert variables into 20+ string, its driving me nuts :)

tried to find solution on google or plugin repository, no result

PS: i know about soutv hotkey, but it cant help me since i have to change already existing strings in code


Solution

  • Added Live Template

    Abbreviation: ++
    Description: Insert variable into string
    Expand with: Enter
    Template text: "+ $EXPR$ +" (do not forget double quotes)
    Edit Template Variable: 
    expression:variableOfType("") default Value: "expr"
    

    settings screen

    You type ++ in a string, press Enter, and template text is added, and you only need to choose a variable. Works like a charm.

    Thanks for the idea, @Meo