Intellij - Reformat Code - Insert whitespace between // and the comment-text? - intellij-idea

I am working with another human being on project from that the professor expects to have uniform code-style. We have written large separate junks of code on our own, in which one has written single line comments without a white-space between the single-line-comment-token and the other one has inserted a white-space. We are working with IntelliJ and have failed to find an option to enable the Reformat Code function, to insert a white-space.
TLDR:
Can you tell us how to convert comments from that to this in IntelliJ?
// This is a load bearing comment - don't dare to remove it
//This is a load bearing comment - don't dare to remove it!

You can do a global search and replace (ctrl-shift-r on windows with default keyboard layout, or Replace in Path under the Edit/Find menu).
Check the regular expression option and enter //(\S.*) as the text to find and // $1 as the replacement. Check the whole project option, and clear any file masks. You can single step through the replacements, or simply hit the All Files option.

Related

How to shorten the first line in the Intellij console?

I want my first line at the top of the console to look like this:
, but mine looks like this, and it's long:
How can I shorten it to like the first picture?
I'm watching Java tutorials on youtube and their first lines ("C:\programs Files\Java\jdk\whatever"...) are always so short and pretty with 3 cute dots in the end, but mine is long and annoying.
You can define the lines which should be folded:
Right click on that line in the console
Choose "Fold Lines Like This"
Click OK
You can also define special keywords/phrases in this menu, where lines, which contains the phrase will be folded with ellipsis (...) at the end.
See the ConsoleViewImpl.java file in the source code of IntelliJ IDEA
This line (execution command) will be automatically hidden in case the string length is more than 1000 symbols.
So, once you add something to the execution command (for example by adding libraries), the execution command is folded automatically.

Intellij: how to convert indents for all files

I know how to convert indent for a single file. I go to edit -> convert indent -> space/tab.
But I want to do this for all files under a directory.
I try click on a directory and then go to edit -> convert indent, but the options are grayed out.
You can use the shortcut Ctrl+ALT+L (Windows/Linux) or ⌥⌘+L (MAC OS X) and select the Rearrange entries option to reformat the code in the current file or reformat a module or directory.
You can also Right-click a module, file, or directory from the context menu and select Reformat Code and also select the Rearrange entries option.
This will convert the indents for all files/directories selected:
This works on most of the Jetbrains IDES (iDea, PyCharm, WebStorm, RubyMine, and so on.)
It seems there is no such dedicated option in IntelliJ, but you could just work around it using a "low-level" Replace All action.
Open the Edit → Find → Replace in Files... dialog
In case you want to convert spaces to tabs, you should
Enter in the Find field (i.e. four spaces (or whatever number of spaces the project is currently indented with))
Press the Regex search modifier (Alt + X)
Enter \t in the Replace field
NB: In case you have valid strings with 4+ spaces in them, they will get replaced too. In most use cases, however, this is not happening.
In case you want to convert tabs to spaces, you should do the same as above, but swap the Find and Replace field contents
NB: Again, if you have valid strings with tabs in them, they will get replaced too. I haven't had this use case, because I've only needed to convert in the opposite direction.
You will probably also want to set a File mask in order not to replace spaces in code-irrelevant files

VFP diacritic removal

I am having a problem with a code responsible for removing (replacing) diacritic in a file, using VPF 9.0.
I am using this command for uppercasing and removing the diacritic:
UPPER(CHRTRAN(ALLTRIM(XNAME),"áäÁÄčČďĎéÉíÍĺľĹĽňóôöőÓÔÖŐŕŔšŠťŤúüűÚÜŰýÝžŽ","AAAACCDDEEIILLLLNOOOOOOOORRSSTTUUUUUUYYZZ"))
The problem is that the first set of characters looks different upon saving. First line is how it should look like, the second is how it actually looks after saving:
"áäÁÄčČďĎéÉíÍĺľĹĽňóôöőÓÔÖŐŕŔšŠťŤúüűÚÜŰýÝžŽ"
"áäÁÄčEďIéÉíÍĺ_ĹĽňóôöoÓÔÖOŕAšŠťŤúüűÚÜUýÝžÄ"
It removes some of the diacritic marks and I can't make it save in the wanted format.
Would you be able to help me with this, please?
Can you please right click the file in project manager and check 'Code page'? By default it should be windows ANSI (1252) and work right.
Edit:
To do from command line.
MODIFY COMMAND myDiacratics.prg AS 1252
when the file comes up, make a change (any change so it would be forced to save) and save. It should save just as you want to.

jEdit in hard word-wrap mode: insert comment character automatically?

Probably quite a niche question, but I believe in the power of a big community: Is it possible to set up jEdit in way, that it automatically inserts a comment character (//, #, ... depending on the edit mode) at the beginning of a new line, if the line before the wrap was a comment?
Sample:
# This is a comment spanning multiple lines. If I continue to type here, it
# wraps around automatically, but I have to manually add a `#` to each line.
If I continue to type after the . the third line should start with the # automatically. I searched in the plugin repository but could not find anything related.
Background: jEdit has the concepct of soft and hard wrap. While soft wrap only breaks lines visually at a character limit, it does not insert line breaks in the file. Hard wrap on the other hand inserts \n into the file at the desired character count.
This is not exactly what you want: I use the macros Enter_with_Prefix.bsh to automatically insert the prefix (e.g., #, //) at the beginning of the new line.
Description copied from Enter_with_Prefix.bsh:
Enter_with_Prefix.bsh - a Beanshell macro for jEdit
that starts a new line continuing any recognized
sequence that started the previous. For example,
if the previous line beings with "1." the next will
be prefixed with "2.". It supports alpha lists (a., b., etc...),
bullet lists (+, =, *, etc..), comments, Javadocs,
Java import statements, e-mail replies (>, |, :),
and is easy to extend with new sequence types. Suggested
shortcut for this macro is S+ENTER (SHIFT+ENTER).

Format TSQL onto one line

Our company uses an old app which reads TSQL from a .INI file. Due to how the app process the INI file the TSQL has to be all on one line. I use Poor Mans TSQL Formatter to get everything nice and tidy for things like SPs, but am wondering if there's something out there to do the reverse - take nicely formatted TSQL and shove it all onto one line (removing carriage returns , line breaks etc).
I'm working in SSMS but also use Notepad++, and will happily use some other editor if it has the functionality.
Using Notepad++ (Without any plugin)
After lot's of googling I found that there are no plugins like TextFX and PoorMansTSqlFormatter are available in x64 bit version of notepad++ even not needed.
Notepad++ --> Write Query --> Edit --> Blank Options --> Remove Unnecessary Blank and EOL.
That's it.
Using Notepad++
Select the statement that is over multiple lines then on the menu: TextFX>TextFX Edit>Unwrap Text
And for even greater ease you can assign it to a keyboard shortcut using the shortcut mapper (Settings>Shortcut Mapper)
You can use the minify comment to remove all the unnecessary space in the Poor Mans TSQL Formatter
[minify]
[/minify]
I like Martin's answer and that is probably the way to go. But I'll point out that you can just use string manipulation to turn carriage returns and line feeds into spaces. This is particularly easy in the later versions of SSMS that enable limted use of regex in the find/replace dialog.
In SQL Server 2012:
Highlight the selected text and use 'Find and Replace' (ctrl + h)
Check: use Regular Expressions
Find: \n
Replace with: LEAVE BLANK