Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make NetBeans automatically format indenting when pasting into a loop/if statement?

When I write my code in NetBeans, there are times when I want to add/remove if statements and loops. However, every time I want to add/remove a statement but keep the content, I have to fix all the indenting for the contained code. Likewise, every time I try to paste code into a statement, the indenting is all messed up and I have to fix it.

Is there any way to highlight the code and fix indentation?

I'm aware that Eclipse has an option to fix all formatting upon saving. I'm not looking for something that changes formatting upon saving, rather only something I can click on the moment I want the formatting fixed. I put an example of what I'm talking about below.

if (condition == true){
    //pasted code
//pasted code
//pasted code
}

or

//other code
//removed if statement
    //original code that is spaced too far right
    //original code that is spaced too far right
//removed }
//other code
like image 314
yuyu5 Avatar asked Feb 10 '16 23:02

yuyu5


1 Answers

Try to paste using Ctrl + Shift + V. If it worked, look at the netbeans options to configure the shortcut you want. To change shortcuts go to : Tools > Options > Keymap

Here is a table of defaults shortcuts in netbeans : https://netbeans.org/project_downloads/usersguide/shortcuts-80.pdf

It might be useful, you can notice the "Ctrl-Shift-V Paste formatted" shortcut.

like image 193
Marc Avatar answered Oct 06 '22 00:10

Marc