How to stop intellij-idea from removing white spaces at end of text lines in my file? - intellij-idea

I am using 2018.1.5 community edition of intellij editor to edit a plain text file.
I am not using a project. I start it, on Linux as follows:
idea.sh my_file.mpl
where my_file.mpl is plain text file.
And this works well, except for one big problem.
I need to have an empty space at end of some lines. i.e. after the line character on some line in the file, I insert some white. I see the space is there, by doing View->Active editor->Show White spaces. I can see the small tiny dotts, showing there are white space character at end of line.
But as soon as I save the file, these white spaces are removed from end of line.
This causes a problem for me (for other reason, when this file is read by another app).
Is there an option to tell it intellij NOT to remove white spaces after the last character on the line?

Go to File->Settings->Editor->General and under Other, set the drop down next to Strip trailing spaces on Save to whatever you wish. For future reference, you can press Ctrl-Shift-A and type a search term to find any menu command or setting very quickly. In this case, "trailing spaces" or "strip trailing spaces" works really well.

Newer PyCharm (2020 and beyond) have slightly different answer than Code-Apprentice's.
Go to File->Settings->Editor->General, and then scroll down to Save Files section. The drop down Strip trailing spaces on Save for: is there. You can select None if you don't want any stripping in no circumstances.
Here is an image showing the setting:

If changing the settings in "Editor > General > Save Files" doesn't work, the below might be useful...
There is a discussion here about a possible bug (or at least confusing scenario) where you have set "Strip trailing spaces on Save for"=None and you still get stripping of trailing spaces, as I did. The comment by Oksana Chumak worked for me - namely, I unticked "Enable EditorConfig Support" in Settings > Editor > Code Style. This seems to allow a config file ".editorconfig" to be used which overrides some settings - also see Andriy Bazanov's answer, quoted below...
NOTE: If you have .editorconfig file in your project, such option can
also be controlled via that file. This file can provide more granular
control over what files are affected by those settings.
Settings from .editorconfig file will OVERWRITE IDE settings (the
whole nature of such files), so if you have such files in your project
and such instruction there, you will have to either disable the
EditorConfig for this project or disable plugin completely (if you do
not care about it at all).

I had my .editorconfig and I have used trim_trailing_whitespace=true. So that was the issue. This is what I did to fix the issue.
[*.md]
trim_trailing_whitespace=false

So here's what worked for me. I wanted intellij to keep trimming whitespaces but to keep the whitespace on blank lines.
First like #Michael-Veksler suggested, I changed intellij's default removal on save.
But it kept trimming the trailing whitespace, that was because in my .editorconfig file I had a trim_trailing_whitespace config turned on. So now I've set trim_trailing_whitespace = false.
Lastly, because I still wanted the editor to trim the trailing whitespaces, just not on blank lines I've added to my .eslintrc.js file the following setting:
module.exports = {
...
rules: {
...
'no-trailing-spaces': [2, { "skipBlankLines": true }]
}
}
And now lint-fix on save just takes care of it

Related

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.

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

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.

How do I display brackets around assumptions in Isabelle/jEdit?

When goals are displayed by Isabelle in ProofGeneral, assumptions are rendered as having brackets around them as so:
In Isabelle/jEdit, however, this seems to have changed to meta-implication arrows:
While I understand the former is somewhat non-standard, I find it much easier to read. Is there a way to modify the behaviour of Isabelle/jEdit to print out goals in the old ProofGeneral style?
The format Isabelle renders its output is determined by Isabelle's "print modes". In ProofGeneral, the default print_mode includes the brackets mode, which renders brackets around assumptions, while the default jEdit print_mode includes no_brackets, which does the opposite.
The print mode can be changed either by setting Plugins > Plugin Options > Isabelle/General > Print Mode to brackets and restarting jEdit, by adding -m brackets to the isabelle jedit command line, or by including in your ~/.isabelle/etc/settings file:
ISABELLE_JEDIT_OPTIONS="-m brackets"
This will result in jEdit displaying brackets like ProofGeneral:
Go into Plugins -> Plugin Options -> Isabelle -> General
then type in brackets in the Print Mode field.
Click Apply.
Then close out of Isabelle and restart it.
You should have brackets around your hypotheses thereafter.

How do I indent multiple lines at once in Notepad++?

In many text editors that are aimed at programmers, if the user has a selection that spans more than 1 line and presses the TAB key, those lines are indented by 1 TAB (or a number of spaces, depending on how the editor is configured).
However, this does not seem to be the default behavior of Notepad++. Is there a way I can do this in Notepad++, or is there a plugin that I can get to allow me to do this?
Edit: Upon additional testing, SHIFT-TAB correctly un-indents the lines as expected, but only a tab simply inserts a tab wherever the carat is. This is in version 5.4.5 Unicode
The problem was with the QuickText plugin. After removing it, indent worked as normal.
Capslock + Tab to indent multiple lines at once. Highlight the text first.
The problem with the new version of QuickText seems to be that it is set to react to the TAB key. Previously it was set to use CTRL-ENTER. If you change the key combination in the shortcut mapper then your TAB key should start working again, and QuickText should also work (with whatever new key you've assigned).
It works fine for my v. 5.4.5 of Notepad++. I just select multiple lines and press TAB.
If you want TAB to be replaced by SPACE than you need to go Settings > Preferences and select Edit Components tab. Next check Replace by spaces check box in Tab Setting section.
Update: In a newer version of Notepad++ this option is in Settings > Preferences > Language section.
If you're using QuickText and like pressing Tab for it, you can otherwise change the indentation key.
Go Settings > Shortcup Mapper > Scintilla Command. Look at the number 10.
I changed 10 to : CTRL + ALT + RIGHT and
11 to : CTRL+ ALT+ LEFT.
Now I think it's even better than the TABL / SHIFT + TAB as default.
I have Notepad++ 5.3.1 (UNICODE). I haven't done any magic and it works fine for me as described by you.
Maybe it depends on the (programming/markup/...) "Language"?
Just install the NppAutoIndent plug-in, select Plugins > NppAutoIndent > Ignore Language and then Plugins > NppAutoIndent > Smart Indent.
Notepad++ will only auto-insert subsequent indents if you manually indent the first line in a block; otherwise you can re-indent your code after the fact using TextFX > TextFX Edit > Reindent C++ code.
in Notepad++v6.1.8 (Unicode) it works after removing the QuickText plugin.
To increase indent - Press and hold TAB
To decrease indent - Press and hold TAB + SHIFT