Wrapping Text into Lines at Word Boundaries

Wrapping text into lines at word boundaries

I believe the function you are looking for is word_wrap. Something like this should work:

<%= word_wrap @comment_text, :line_width => 56 %>

You can combine that with gsub to get the indentation you desire:

<%= word_wrap(@comment_text, :line_width => 52).gsub("\n", "\n    ") %>

But you should probably move that into a helper method to keep your view clean.

Stop Vim wrapping lines in the middle of a word

:help wrap

This option changes how text is displayed. It doesn't change the text
in the buffer, see 'textwidth' for that.
When on, lines longer than the width of the window will wrap and
displaying continues on the next line. When off lines will not wrap
and only part of long lines will be displayed. When the cursor is
moved to a part that is not shown, the screen will scroll
horizontally.
The line will be broken in the middle of a word if necessary. See
'linebreak' to get the break at a word boundary.

:help linebreak

If on Vim will wrap long lines at a character in 'breakat' rather
than at the last character that fits on the screen.

:help breakat

'breakat' 'brk' string (default " ^I!@*-+;:,./?")

So, :set linebreak and it should work out of box. Or you can restrict breakat to just break on spaces, instead of spaces+punctuation.

Wrap lines of text to a specified character length limit with support for ansi color codes

# brew install cpanm
cpanm App::ansifold
# cpanm -V # to find install dir
# /usr/local/Cellar/perl/5.30.1/bin/ansifold
# use just like fold: `ansifold -s -w 80`

Example screenshots of ansifold wrapping text correctly:
Sample Image
Sample Image

How can I switch word wrap on and off in Visual Studio Code?

Since v1.0 you can toggle word wrap:

  • with the new command editor.action.toggleWordWrap, or
  • from the View menu (*View** → Toggle Word Wrap), or
  • using the ALT+Z keyboard shortcut (for Mac: +Z).

It can also be controlled with the following settings:

  • editor.wordWrap
  • editor.wordWrapColumn
  • editor.wrappingIndent

Known issues:

  1. renderLineHighlight should highlight the entire logical line

If you'd like these bugs fixed, please vote for them.

In HTML, is it possible to insert a word wrapping hint?

Use ­ in words or <wbr> between words, as <wbr> won't introduce a hyphen.

See also:

  • quirksmode: <wbr> compat list


Related Topics



Leave a reply



Submit