How to make hard wrap guide force word wrap in .txt files?

I figured out how to set (soft) word wrap on .txt files, but that only wraps the edge of the file tab's visible border (on the screen), but I'd prefer to have those wrap by the "Hard wrap guide", as mentioned in Preferences > Editor > General > Appearance, and pictured in Editor > Color Scheme > General > Hard wrap guide:

As you can see, that "hard wrap guide" doesn't actually wrap anything (as it probably wasn't intended to by default), but I'm not finding a setting to make .txt files soft-wrap by that line instead of by the file tab visible border (which is too arbitrary or manual):

Here's the setting for soft-wrapped files:

Also, it's annoying that the settings for hard wrap and soft wrap are named variously with or without the hyphen in settings :/ (nevermind that settings are called Preferences on Mac and Settings on Windows)... it makes it difficult to find things when standard or consistent names aren't used for things.

1
5 comments

Hi there,

Settings/Preferences | Editor | Code Style

P.S. There is no Code Style for TXT files: "Other File Types" will be used for them, which has only the basic indentation settings. Therefore do not expect much for TXT files in this regard.

For PHP and quite a few other languages there is a separate option (that can overwrite the global one from the first screenshot)

https://www.jetbrains.com/help/phpstorm/settings-code-style-wrapping-and-braces-common.html#rightMargin

 

0

> There is no Code Style for TXT files: "Other File Types" will be used for them, which has only the basic indentation settings

So, this is a problem because I've been using .txt for notes and scratches for a while now, and the reason is because PHPStorm is better than my other editors at just letting me fuss around with plain text (TextMate is good but not as much). If .txt files are treated like "Other File Types", even though it's maybe the most well-known, then how is it different than having file extension .blob or .whatever on my notes and scratches? Regardless of the file extension, I need basic plain text editing features like word wrap.

So, do I define .txt as its own file type in the editor so that I somehow get more power with it?

Also, I'm not sure if JetBrains is mixing or misunderstanding hard wrap and soft wrap; hard wrap is when newlines are added to the file (which will be saved to the file) when the text hits some wall like the viewport edge or a style guide marker, and soft wrap is when it just adds newlines to the text at those points but doesn't save them to the file.

The "Hard wrap guide" seems misnamed, because it doesn't actually cause newlines to be added to the file, and it certainly isn't wrapping anything at all in my text by default (hard or soft). So, I need some solution for notes and scratches, regardless of where I've added them (within the project file tree or within the Scratches file tree or within a Favorites bookmark file tree), because I need a plain text editor for many different things such as log file chunk perusing, or editing some error output from like a website response to make it readable for someone else, or things like that (I'm sure you can imagine but I don't expect you to).

I mean, Notepad on Windows does soft wrap, word wrap, but of course I just resize the window, but I don't want to be resizing the PHPStorm window for the random text file I need to muss around with or save or delete etc.

 

1

So, do I define .txt as its own file type in the editor so that I somehow get more power with it?

I do not think so... since you cannot create Code Style entry for it. Unless you code it all via custom plugin (where you code all that) of course.

... hard wrap is when newlines are added to the file (which will be saved to the file) when the text hits some wall like the viewport edge or a style guide marker, and soft wrap is when it just adds newlines to the text at those points but doesn't save them to the file.

Correct.

The "Hard wrap guide" seems misnamed, because it doesn't actually cause newlines to be added to the file, and it certainly isn't wrapping anything at all in my text by default (hard or soft).

Hard wrap: works for me on typing:

The text below was wrapped automatically on typing (file named "text.txt"):

Soft wrapping in action (html file) -- the line gets wrapped on the viewport; notice the big empty space between the line numbers in the gutter and extra symbols at the end and at the start of the soft-wrapped line (configurable; as well as left side alignment). Exactly the same will be present in a plain text file, just no syntax highlighting.

P.S. In code (e.g. HTML / PHP) the hard wrap is used to decide when it's time to split the long line into smaller pieces so they fit the desired line length.

An example:

  • function/method declaration or function/method call that has a lot of parameters (especially when type hinted with some long class names or parameters)
  • HTML tags nesting and wrapping
0

OK thanks for the clarification.

However, the "Wrap on typing" checkbox after the "Hard wrap at # columns" is where JetBrains is confusing; hard wrap is not an optional thing where you choose whether it's soft wrap or not. Hard wrap literally adds a text newline to the file upon save where the wrap line is. So having "Hard wrap at 80 columns" I would expect the editor to add a newline where the wrap line is for the text regardless of whether the text was typed at the time or pasted. The "Wrap on typing" checkbox muddies this, making me think that's when the hard wrap happens, or the hard wrap of the previous setting only happens for text that you're typing (not pasting)... either way doesn't make sense or has a misnomer.

If "Hard wrap at # columns" means "add a text newline to the file for text at # columns or later regardless of whether the text is being typed or pasted", then that setting makes sense. If it only hard wraps at # columns for text (regardless of being typed or pasted) when "Wrap on typing" is checked, then that makes "Hard wrap at # columns" only hard wrap for pasted text? Or does it only activate hard wrapping at all when "Wrap on typing" is checked? And does that apply only to text that you're typing, or also to pasted text? Something is either not worded right with these two settings, or their logic is wonky.

Soft wrapping is not always relegated to viewport on editors; that can also happen with a wrap guide line, even though it appears to be used as a conditional/arbitrary hard wrap guide line. JetBrains calls that guide line the "hard wrap" guide line... but what I'm looking for is a soft wrap automatically at the # of columns that I specify. I don't want newlines saved to the file, I just want the editor to display word wrap at the specified # of columns regardless of viewport width.

Even if you're describing everything perfectly accurately here, it appears the editor does not support what I'm looking for with .txt files, and on top of that appears to be wording things strangely or inconsistently or inaccurately.

Anyway, the problem with checking "Wrap on typing" in Editor > Code Style > General is that it appears it'll apply to any file that doesn't have its own specific file type (extension) wrap settings (whether by default or manual setting). I simply want .txt files to soft wrap at a certain column, not the viewport (though it would be nice if they soft wrapped if the viewport showed less columns than the wrap line).

If I've missed something, please point it out and accept my apology. It just looks like the editor has some strange things with wrapping that other editors seem to handle just fine, but I prefer PHPStorm's other features and its keyboard shortcuts.

0

...regardless of whether the text was typed at the time or pasted.

This may depend on what you have for "Settings/Preferences | Editor | General | Smart Keys | Reformat on paste". I have it set to "None" (as I do not like how it sometimes reformats it).

"Wrap on typing" means that it will apply that as you type (NOTE: I do not know how it will behave if you start typing in the middle of the string: sure, it will wrap it .. but will it affect the next line as well (reformat the whole paragraph) -- do not think so).

For me: hard wrapping means the max line length and it gets applied when you complete the statements/snippets (writing the code) or calling Reformat. Plain Text file has no Reformat support.

but what I'm looking for is a soft wrap automatically at the # of columns that I specify.

Here the soft-wrap works on the editor width only and not the visual guides.

Anyway, the problem with checking "Wrap on typing" in Editor > Code Style > General is that it appears it'll apply to any file that doesn't have its own specific file type (extension) wrap settings (whether by default or manual setting).

Correct.

I simply want .txt files to soft wrap at a certain column, not the viewport (though it would be nice if they soft wrapped if the viewport showed less columns than the wrap line).

I see no other choice but to submit a Feature Request ticket to the Issue Tracker: PhpStorm Issue Tracker , IntelliJ IDEA Issue Tracker -- tickets for the platform-wide functionality like text editing, terminal etc will be tracked here. You can filter by the subsystem:

Seems related:

P.S. There was a comment in one of the tickets (long time ago: 6-7 years or so). It was about auto-wrapping the text for PHP TODO / PHPDoc / plain comment block that would allow the whole text/paragraph to be re-flown (reformatted) on typing. So it does not matter where you start typing (end of the line, start or at the middle) it will always keep that text nicely formatted. There was a GIF image with how it works in some another advanced text editor (SlickEdit is my best guess right now). Sadly cannot find that ticket now, but might be this one (just the link does not have a demo any more): https://youtrack.jetbrains.com/issue/WI-3713

Anyway, partially related (PHP-specific) tickets:

And just to repeat: for plain text, look at IDEA tracker and fell free to submit a new Feature Request ticket.

0

Please sign in to leave a comment.