Cole
Cole

Reputation: 2815

Eclipse Java shortcut for "printf"?

When coding in Java in Eclipse, is there a shortcut similar to typing "syso" and pressing CTRL+Space for System.out.println(), but for printf instead of println?

Upvotes: 11

Views: 9460

Answers (5)

rahul_bhise
rahul_bhise

Reputation: 3

If you name the new Templates as pzf (you can also try different combinations and see if that doesn't match any other Template names) it will print the statement right away, without having to press enter. Also, I added inverted commas and commas.

System.out.printf("${word_selection}${}",);${cursor}

Upvotes: 0

Ali Nehme
Ali Nehme

Reputation: 1

I created my own System.out.printf() shortcut on Eclipse.

Simply, go to Windows > Preferences > Java > Editor > Templates

Click on New, then fill the form with the following information:

Name: the shortcut you would like to use in the editor (e.g. printf)

Description: print formatted text (or any other description)

Pattern: System.out.printf(${word_selection}${});${cursor}

That's it! Now you can just type "printf" in your editor, followed by [Ctrl + space], then [Enter], and the editor will place a System.out.printf() for you.

Upvotes: 0

Sem
Sem

Reputation: 146

You can make your own for printf:

In preferences choose Java->editor->templates.

Upvotes: 4

Ulrich Palha
Ulrich Palha

Reputation: 9509

I don't see one in the default completion templates, but you can create your own template

Upvotes: 2

RanRag
RanRag

Reputation: 49537

you can create your own using eclipse template functionality.

To create your own template take a look here Window->Preferences->Java->Editor->Templates.

For example the sysout functionality has this template:

System.out.println(${word_selection}${});${cursor}

you can create similar for System.out.print()

Upvotes: 20

Related Questions