How to make my own commands and shortcuts in Eclipse?

Asked

Viewed 488 times

4

What I mean by my question is that, for example, when I use sysout and Ctrl+Space the method line System.out.println(); is ready for me to use, reducing my time to type everything.

I wonder if you have how to make my own commands, using some keyword and the Ctrl+Space, to call other methods I want. For example metodoUm and Ctrl+Space calls a certain method that I want.

  • 1

    has yes, see this link: http://www.devmedia.com.br/criando-shortcuts-no-eclipse/2150

  • It’s almost what I wanted Peter, is there any way I can create my own commands? The ones available in Keys help, but for example, I thought of typing "functionOm" and Ctrl+Space and he would type the text for me corresponding to the function I want. I imagined that this is how it happened with "sysout", it just typed a text that corresponds to the function I want. So I could modify this text and make my own. But your link left me on the right track, thank you!

1 answer

6


The name of this is "Code Template", to create a go in Windows Prefences Java Editor Templates, to get to the following screen:

inserir a descrição da imagem aqui

Click "New" to create your template code. As an example, I created a template to automate the creation of an attribute and a method to make a class a Singleton.

inserir a descrição da imagem aqui

Follow the code if you want to copy:

private static ${primary_type_name} instancia;
public static ${primary_type_name} getInstancia() {
    if (instancia == null) instancia = new ${primary_type_name}();
    return instancia;
}

Now in a newly created class, type the template name Ctrl + Space:

inserir a descrição da imagem aqui

Then confirm with the Enter, your class will look like this:

inserir a descrição da imagem aqui

Note that you can greatly increase your template power if you use variables, as for example in the above case I used the ${primary_type_name}, that replaces the code part with the class name. By clicking "Insert Variable" you will have an extensive list of variables you can use.

  • 1

    Thanks Math! That’s right, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.