Netbeans - Whitespace - netbeans

I have to use Netbeans which I never used before and there are 2 format settings driving me crazy :/
1) Dereferencing [i+1] is turned into [i + 1]. I hate these two whitespaces.
2) All my comments are directly put behind the code and all my tabs for ordering comments are lost.
I know I can set it somewhere in Tools->Options->Editor->Formatting but even after searching and googling (crazy word) I did not find this setting.

For 1)
This is in Tools -> Options -> Editor -> Formatting
The select Java as the language and "Spaces" as the Category.
It's in the section "Around Operators" and the one you are looking for is "Binary Operators". That however applies to any occurance of e.g. + (or - or other similar operators) not only between brackets. E.g. if that option is disable i = x + y is changed into i = x+y
I have no idea what you mean with 2)

Related

How to tranform css hex to uppercase in vscode?

I'm just using vscode prettier, and I was told that hex value should be uppercase as company's standard. I've been through a search and I found their github-issue
that states,
" Personally I prefer uppercase too, but I was asked to do lowercase... But changing this would cause a lot of unnecessary churn for all Prettier users... this decision has been made and is not going to change. An option won't be added." - Sep. 29,2018
So basically, prettier transformed hex value to lowercase, and does not provide an option to change it to uppercase.
I want to ask, have they change their decision now and made an option to transform css hex value to uppercase? And if theres no really option for this in prettier, is there any alternatives to achieve this?
My basic alternative that I used is the idea of #rioV8, however I would prefer to use replace field instead of Transform to UpperCase, I think that would be more quick.
I would like to provide this as answer because it's at least working.
In vscode find #(?:[0-9a-fA-F]{3}){1,2} using regular expression, and replace it with \U$0.
Updated: how to auto transform after save
Follow this link: How to automatically run a "find and replace" after save?
Since \U$0 did not work well, we looked for alternatives.
Search by regular expression
Open a search window with cmd + shift + f, click .*, and execute a regular expression search with #(?:[0-9a-fA-F]{3}){1,2}.
Select the target string
In the search results window, use cmd + a to select all and cmd + shift + l to select the target string.
Open the command palette
Open the command palette with the cmd + shift + p.
Convert to upper case
Type upperor lower on the command palette and execute.

Automatically hard wrap lines at column in VSCode

How can I automatically hard wrap lines in VSCode? By that I mean if a line reaches a specified column, automatically insert a newline at the word boundary closest to that column without going over. Vim has a setting called textwidth that does this that I like to use when editing Markdown. It doesn't seem like VSCode does, as far as I can tell. It just has ways to control softwrapping.
VSCode doesn't support this out of the box. But you can install the Rewrap extension, which allows you to format the block that your cursor is currently in by pressing Alt + Q.
Rewrap requires no further settings, since it reads VSCode's settings to obtain the column at which to break.
Rewrap also supports automatic wrapping (off by default): https://github.com/stkb/Rewrap/wiki/Auto-wrap
Unfortunately, VSCode doesn't have this feature yet. But, we still can make it to be as close as vim automatic word wrapping beautiful feature.
First Step
We need to setup soft word wrap feature in VSCode.
Open VSCode Settings via Code => Preferences => Settings.
Add these 3 lines of editor settings.
"editor.wordWrap": "wordWrapColumn",
"editor.wrappingIndent": "same",
"editor.wordWrapColumn": n
Don't forget to change (n) with your preferred length of columns line. For me, I feel more comfortable to set it to 60.
Save this setting.
The main purpose of this first step is to make us feel more comfortable when we're typing because we don't need to manually type Enter and see a long line of text.
Second Step
We need to install Vim emulation for VSCode and set vim textwidth.
Install Vim emulation via VSCode extensions.
Open VSCode Settings via Code => Preferences => Settings.
Add this line of vim setting.
"vim.textwidth": n,
Don't forget to change (n) with your preferred length of columns line. For me, I will set this to be the same with (n) in the first step.
Save this setting.
Actual Use
When you finish to write your whole document, you can format it to be hard wrap lines using this way.
Block all text using visual line mode (Shift + v)
Type 'gq'
Now VSCode support auto "soft" wrapping out of the box.
Settings --> Text Editor --> Last 3 options (as on today) is for autowrapping.
Word Wrap (Controls how lines should wrap)
Word Wrap Column (Controls the wrapping column of the editor)
Wrapping indent (Controls the indentation of wrapped lines)
By default Word Wrap is off.
As of 2020 and if you're using the Prettier - Code formatter plugin:
Go to Plugins -> Find Prettier -> Cog -> Extension Settings -> Prettier: Print Width Fit code within this line limit and set to whatever you want. By default it's 80.
When you save the file, Prettier will format automatically.
Hard Wrap Comments
Use the Rewrap extension.
Soft Wrap Code
Add the following setting (replace column width with your preference): "editor.wordWrapColumn": 100
Then add either "editor.wordWrap": "wordWrapColumn" (wraps at the column) or "editor.wordWrap": "bounded" (wraps at either the column or the viewport).
Hard Wrap Comments and Soft Wrap Code
Unfortunately the extension and VSCode settings do not play nicely.
Feel free to upvote this feature request.
There is currently an Open request for this in the VS Code Issue tracker on GitHub, You Can Find It Here
Most of these didn’t work for me, but I found the extension Vsctoix, which does.
We start out with line breaks at column 80:
Mechanisms such as a “windfall clause” help distribute riches within particular
futures. But for a windfall clause to be useful, many conjunctive assumptions
have to be true. We present a new method to borrow against potential future
windfalls today, when they have greater marginal use. The method also increases
the probability and thus the expected value of the windfalls.
Then we execute “IX: Join Lines” (no parameter):
Mechanisms such as a “windfall clause” help distribute riches within particular futures. But for a windfall clause to be useful, many conjunctive assumptions have to be true. We present a new method to borrow against potential future windfalls today, when they have greater marginal use. The method also increases the probability and thus the expected value of the windfalls.
And then “IX: Break Line At” with parameter 100:
Mechanisms such as a “windfall clause” help distribute riches within particular futures. But for a
windfall clause to be useful, many conjunctive assumptions have to be true. We present a new method
to borrow against potential future windfalls today, when they have greater marginal use. The method
also increases the probability and thus the expected value of the windfalls.
It would be neat if it respected paragraph breaks and did both steps at once, but so far it’s the only extension that works for me – except I haven’t tried the vim emulation yet.
You can do this without any extension. You just use two regex search-and-replace.
Isolate the lines you want to rewrap by moving them to a separate file.
Join all the lines into one line. For example, ctrl+h, "\n" ==> " ". Note: make sure regex is enabled (the dot star icon)
Split the line into multiple lines. For example, ctrl+h, "(.{100}) " ==> "$1\n". Notice the space after the paren.
Copy the lines back to the original file.
There are many variations on this technique. For example, you could using comma instead of space "(.{100})," ==> "$1,\n". You could use Find in Selection alt+L instead of using a temp file.
Edit: (below answer might be for a soft wrap, see here for difference between soft and hard wrap: https://stackoverflow.com/a/319932/9481613)
In my version it is Preferences -> Settings then scroll down to "Editor: Word Wrap" where a dropdown box is available from which I selected wordWrapColumn. After choosing this and closing, when I click on View now at the bottom it says Word Wrap Alt+Z.
If anyone is running having issues, accessibility support/screen reader may need to be disabled. Go to preferences >> text editor >> accessibility support and toggle it off.
You can easily set the column limit using ColumnLimit member in C_Cpp.clang_format_fallbackStyle in settings.json (You have to install Microsoft C/C++ extension)
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: WebKit, IndentWidth: 4, ColumnLimit: 80 }",
Then you can format the file using Shift + Alt + F
There are many options you can change in this format feature
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: WebKit, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Attach, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 80, AccessModifierOffset: -4 }",
Name of the predefined style used as a fallback in case clang-format
is invoked with style file but the .clang-format file is not found.
Possible values are Visual Studio, LLVM, Google, Chromium, Mozilla,
WebKit, Microsoft, GNU, none, or use {key: value, ...} to set specific
parameters. For example, the Visual Studio style is similar to: {
BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4,
BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false,
IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4,
NamespaceIndentation: All, FixNamespaceComments: false }
Before
void Proc::Memory::getSramOff(const char* mem_name, uint dataSize, uint addrBits, uint& noOfBytes, uint& sram_off)
After
void Proc::Memory::getSramOff(const char* mem_name, uint dataSize,
uint addrBits, uint& noOfBytes, uint& sram_off)

Netbeans 7.0.1 Word Wrap

I know there are a bunch of posts about this already, stackoverflow: word wrap in netbeans, for one, and there are some people that say it is already included in netbeans 7, but for the most part they are all old, or inconclusive. I use netbeans 7.0.1 and the included word wrap is half-assed and glitchy at best. Going to Tools > Options > Editor > Formatting > Line Wrap and setting it to either "After Words" or "Anywhere" both result in practically the same sort of wrapping and neither one is very reliable. On occasions it will wrap as expected, but more often than not you can end up with anywhere from one word to an entire paragraph past the vertical scrollbar. Is there something I am missing or is that really the way that's supposed to work?
I'm still looking and will post any significant finds, but does anyone know of a way to fix this, or a plugin to install for it, or anything? I would have figured after 4 years of inquiries (2008 is the oldest post I've found about this) netbeans would have fixed it :(
BTW: Not looking for reasons why my code shouldn't be more than 80 character long, there's no helping it sometimes and that answer isn't helpful. I have also tried adding "-J-Dorg.netbeans.editor.linewrap=true" in the netbeans.conf file, but from what I gather that is for enabling the feature in older version and did nothing in mine (I removed it).
On Netbeans 7 and 8, you can use Tools/Options/Editor/Formatting/LineWrap.
It can only be globally enabled.
you can do it from:
1) Tools -> Options -> Editor -> Formatting(Tab)
2) Select Your Language in "Language Drop down"
3) Select "Wrapping" from "Category and do what ever you want
Note: this is for Windows OS
I have done it in netbeans 8.0
Goto -> Tools-> options-> Editor-> Formatting-> language(dropdown-All languages) -> Category(dropdown-Tabs and indents) -> Line wrap(After word)
Make sure you re-open the file to see the change.
In case any one is looking for this with NetBeans 8 on OSX and ends up here, it's preferences/Options/Editor/Formatting/LineWrap
you can do it from:
1) Tools -> Options -> Editor -> Formatting(Tab)
2) Select Your Language in "Language Drop down"
3) Select "Tabs and Indents" from "Category
4) Dropdown" select any of the desired option from "Line Wrap drop down"
i.e After words or Anywhere
Note: this is for Windows OS
In Netbeans 7.2 it's actually, "Wrapping" instead of "Line Wrapping" and it's "If Long" instead of "After Words", but that probably doesn't answer your question.
You posted this almost one year ago, and you still haven't found anything yet?
I don't like how they decide to wrap by way of creating actual new lines in the editor. I would prefer if it just line-wrapped but you didn't have to make a new line - like, what you have with Notepad. However, I would prefer if you had a symbol to show that you're line wrapping on the next line, like I have seen in other IDE's before.
I done in Netbeans 8.0.2 as following way :
NetBeans->preferences/Options/Editor/Formatting/LineWrap
Hope this is useful.

Is there a way to fold eclipse sub-blocks like an "if" statement?

Currently Eclipse only fold the java doc and at function level, but when reading long methods, there could be quite a lot of if/else etc, is there a way to fold them?
I found the Coffee-Bytes plugin. I downloaded it from this link and found this guide by the author, for using it.
You can find more details in these references:
What code folding plugins work on Eclipse 3.6?
How to use Coffee-Bytes code folding
in updated versions of Eclipse
Change folding preferences at:
Window -> Preferences -> C/C++ -> Editor -> Folding -> Enable folding of preprocessor branches (#if/#else)
Enable folding using ctrl + shift + /
No, in the Preferences Dialog (Menu Window/Prefernces): Java/Editor/Folding you may choose,
Comments
Head Comments
Inner Types
Members and Imports
if Enable Folding is checked.
If you wan't to do this because the blocks are so long that can't reconize the structure
you should consider to split if/else blocks into methods using Alt-Shift-M (Extract Method)
It appears Eclipse does not have built-in support for folding if/else statements but allows folding for other more complex cases like Anonymous inner classes. Try looking for plugins like this one (last modified 2007, try it if it supports your Eclipse version).
Ok, this is a little bit older, but maybe someone could find this useful:
In most cases you can surround the piece of code by an additional pair of scope brackets, and to remember what you folded you can add a line comment.
For example, if you want to collapse the following:
int SectionA_var1;
int SectionA_var2;
int SectionA_var3;
int SectionA_var4;
int SectionA_var5;
int SectionB_var1;
just add the brackets an the comment:
{ // SectionA
int SectionA_var1;
int SectionA_var2;
int SectionA_var3;
int SectionA_var4;
int SectionA_var5;
}
int SectionB_var1;
Then you get the (-) sign and you can collapse the whole section to this:
{ // SectionA[...]
int SectionB_var1;
No plugin necessary, and until now I had no situation where this gave me any downsides, except that you cannot use it on a top level declaration to collapse methods.
For now, there is built-in function.
Click "Window->Preferences->C/C++->Editor->Folding" and then enable appropriate option you want.
Apply, close and either refresh project or reopen eclipse.
As weird as it looks like, sounds like developers never thought about that. if you have a big if statement or any switch/loop ... just use notepad++ to be able to fold/unfold
For Python, i.e. Eclipse/PyDev, go to Windows > Preferences > PyDev > Editor > Code Folding and check all the boxes.
Fold java source code like "if else for" statement
install pluins com.cb.eclipse.folding
restart your Eclipse make sure the pluins enabled
Click "Window->Preferences->Java->Editor->Folding"
Select folding: select "Coffee Bytes Java Folding"
Switch to "User Defined Regions"
"Start Identifier" = { ; End Identifier = }
click "Apply and Close"
Reopen java source editor you will see "if" or "for" block is collapsable

Eclipse Shortcut to Split Long Strings

I swear I've seen someone do this, but I can't find it in the various lists of shortcuts.
Given:
String s = "A very long ............................ String";
Is there an Eclipse shortcut to turn it into:
String s = "A very long ............................ "
+ "String";
Yup - just hit return when your cursor is in the middle of the string.
Admittedly that puts the + at the end of the first line instead of the start of the second, which is irritating if your style guide demands the latter, but if you're not fussy it's great :)
All the formatting templates in Eclipse will put the plus on the next row (which I find really annoying), so you can simply apply the code formatter and the plus will end up on the next row.
There may be a Quick Fix (Ctrl + 1) for this as well.
I was amazed in 3.4 to discover that there are Quick Fixes to transform +-based string concats into uses of StringBuilder or MessageFormat. Brilliant!
Also you can format code using regular expression. Select expression, press Ctrl+F and use:
Find: "\s*?\+\s*?\R(\s*?)"
Replace with: "\R$1\+ "
☑ Regular expressions