5

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
1
  • check Preferences -> Editor -> Formatting and see if there's an option to format when completing a scope. In intelij if I want to format a section of code, I delete the enclosing } and then retype it to format all the code that braces contains. Commented Feb 10, 2016 at 23:58

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.