How to remove all whitespace from a text file - intellij-idea

I am trying to remove all whitespace using Intellij IDEA Ultimate 2019.1.2. I have a simple text file with json data.
I've tried using find and replace with regex enabled, but to no avail.

You can press the CTRL + R to open the replace panel, and enter a whitespace in the first input field, leave the second input field empty.
Then click the replace all button.
If you want remove all whitespace including line break, you can enter \s and enable the regex option.

Related

Intellij how to delete all line containing annotation?

I want to delete all lines that contains annotation. I see there is a shortcut to delete line/selection. But how do i pass regex to the delete line shortcut so that all line that starts with # gets deleted?
I want to use like this
^#
You have to use replace option.
Use Ctrl+R to open replace option, select regex(at the left side of search box there is a * sign). Enter #.*$ in replace box. Keep the replace with box empty.
The Regex means any line starting with # followed by zero or more characters(digit/non digit/letter etc) and ended by end line.

Add suffix after specific after some characters and after number of characters Notepad++

Id like to add .pdf text after
these characters: =pd
and after 6 characters behind characters above in Notepad++
for example:
for text:
=pd374069
=pd422552
add suffix:
=pd374069.pdf
=pd422552.pdf
Press ctrl+h or go into the find/replace window. Select Replace tab and choose the Regular Expression option.
In the find text box enter (=pd\d{6}(?!\d))
In the replace window enter \1\.pdf
It will transform
SPEC SHEET=pd374053;MANUAL=pd374069;SPEC SHEET=pd422552
into
SPEC SHEET=pd374053.pdf;MANUAL=pd374069.pdf;SPEC SHEET=pd422552.pdf

How to replace all tab characters in a file by sequences of white-spaces in intellij?

Given a file in my project, I want to be able to replace all of the tab characters in the file with white spaces. Is there any way to do this in intellij?
Go to Edit | Convert Indents , and then choose To Spaces or To Tabs respectively. It's in the documentation: Changing identation
Replace only tabs used for indentation
Ctrl + Shift + A
type "To Spaces" > Enter
Replace all tabs
Ctrl + R
check Regex
Enter \t and spaces
Replace all

Is there a functionality like Sublime's "HTML: Encode Special Characters" in Intellij IDEA

I'm looking something like the functionality given in Sublime Text by the shortcut (windows) Ctrl + Shift + P named "HTML: Encode Special Characters" but in IntelliJ IDEA. This functionality is able to transform this (as a example):
I'm a special character phrase "áéíóú ñ"
Into this:
I'm a special character phrase "áéíóú ñ"
Only by surrounding the specified text and pressing the shortcut key combination given above (again, in windows Ctrl + Shift + P).
Any thoughts?
UPDATE (07-04-2016)
By now, Intellij Idea support this feature natively (version 2016). You need to select the text you want to transform and (in OSX) Cmd+Shift+A and type "Encode" then select the action "Encode XML/HTML Special Characters"
The only caveats are that this only works (to my knowledge) in html strings.
It is not supported by IntelliJ directly, but a plugin called String Manipulation can help
From the plugin page:
Provide actions for text manipulation:
Un/Escape selected Java text
Un/Escape selected JavaScript text
Un/Escape selected HTML text
Un/Escape selected XML text
Un/Escape selected SQL text
Un/Escape selected PHP text
Trim selected text
Trim all spaces in selected text
Remove all spaces in selected text
De/Encode selected text as URL
Convert selected text to Camel Case
Convert selected text to Constant Case
Capitalize selected text
Encode selected text to MD5 Hex16
De/Encode selected text to Base64
Remove empty lines
Convert non ASCII to escaped Unicode
Convert escaped Unicode to String
Grep selected text, All lines not matching input text wil be removed. (Does not work in column mode)
Increment/Decrement selected text. Duplicate line and increment/decrement all numbers found.

How to remove unnecessary blank line on code formatting in IntelliJ?

Is it possible to remove empty/blank lines using code formatting in Intellij IDEA?
Yes. It is possible to configure the number of blank lines in the settings menu (CTRL+ATL+S): File -> Settings -> Editor -> Code Style -> Java(or Scala or whatever your language is) -> Blank Lines
File >> Setting >> Editor >> Code style java >>Blank lines tab
You should change to 0 in code label(as picture), It would remove all unnecessary blank line when press format shortcut: ctrl + alt + L
You can find and replace with regex option also ^(?:[\t ]*(?:\r?\n|\r))+. It searches all empty lines in file. You need to just replace it with empty
I use regular expressions to remove extra blank lines from the code. Here are the instructions.
Open Find and Replace dialog. Use shortcut CTRL+SHIFT+R.
In the search box type ^(?:[\t ]*(?:\r?\n|\r)){2,}. This will search for two ore more blank lines.
In a replace box type \n. This will replace with one blank line.
Open Reformat Code dialog and click Run. Use shortcut CTRL+ALT+L.
This works on all JetBrains IDEs. Use the screenshot as referece.
Just in case it helps someone using newer versions of Intellij, in Intellij IDEA 2016.2.4 it is File -> Other Settings -> Default Settings -> Editor -> Code Style -> Java(or Scala or whatever your language is) -> Blank Lines
For those trying to remove blank lines at the end of the file, this became a feature as of August 2020.
The proper place to configure this action is under Settings|Editor|General|On Save. Check "Remove trailing blank lines"