2

Imagine a 30-character line shown in a 20-character wide window. How can I soft wrap it at the 25th column?

With :set nowrap

|01234567890123456789|0123456789
|       window       |

After scrolling till 25th character.

01234|56789012345678901234|56789
     |       window       |

Desired behaviour:

01234|56789012345678901234|
     |56789               |
     |       window       |

I tried :set columns with a large number but it messed up other elements like statusline.

A similar question instead concerns with setting column number smaller than the window width.

4
  • Why not turn on wrap, which does this? You can scroll left and right with zl and zh i think
    – D. Ben Knoble
    Commented Feb 27, 2021 at 14:54
  • @D.BenKnoble :set wrap won't have the specified behavior (3rd example).
    – tejasvi
    Commented Feb 27, 2021 at 15:23
  • There is no built-in way to do what you want, and I don't think that implementing that with a plugin would be possible (I could be wrong tho)
    – statox
    Commented Mar 1, 2021 at 15:42
  • Vim doesn't really have any soft wrapping capabilities. See: github.com/vim/vim/issues/1847 Commented Mar 2, 2021 at 5:06

1 Answer 1

1

I thought I found a good example of what can't be done with Vim. (Un)fortunately I was wrong.

The specified behavior can be accomplished by:

  1. Concealing first n characters of every line. E.g. :syn match Concealed '^.\{25\}' conceal
    1. n is determined by the current 1 + virtcol(".") - wincol().
    2. This needs to be updated on every WinScrolled (Neovim only) event.
  2. Setting concealcursor=nvic.
  3. :set wrap
2
  • This is an abomination. I love it!
    – Rich
    Commented Mar 3, 2021 at 13:53
  • The answer could be improved by a). including the code! b). adding a plain-English explanation of how it works.
    – Rich
    Commented Mar 3, 2021 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.