Repository: neovim
Issue: :Man softwrap (vim.g.man_hardwrap = 0) breaks table formatting
Labels: bug,plugin,runtime

## Problem

**TL;DR**: soft wrap (`vim.g.man_hardwrap = 0`) breaks the formatting of wide tables.

My use case is to read man pages in Neovim with its great navigation.

It is common to resize the buffer displaying the man page. Either from Neovims great buffer resizing capabilities itself or from outside, e. g. terminal emulator or tiling window manager. While all code is properly wrapped on any resize, man pages often end up strangely formatted.


### Problem with Hard Wrap

When using hard wrap (`vim.g.man_hardwrap = 1`) the man page ends up badly formatted even by the smallest resizings.See following example, I opened neovim in a vertical split and opened a man page with `:hide Man systemd.unit`.

It was nicely formatted at first:
![hardwrap_pre-resize](https://github.com/neovim/neovim/assets/121407246/ede2b942-7841-4b91-8073-40ec119e6f21)

But after a resize of 4 fields (`<C-w>4<`) many sentences broke for one word and created a bad formatting.
![hardwrap_post-resize-4](https://github.com/neovim/neovim/assets/121407246/20132676-ab1a-426e-a4fb-cd00f8c77d08)


### Problem with Soft Wrap

The solution is to use soft wrap (`vim.g.man_hardwrap = 0`). Man pages with soft wrap work great, but the tables are poorly formatted.

View of `systemd.unit` in a narrow window:
![softwrap_splitcreen](https://github.com/neovim/neovim/assets/121407246/c86fa618-d4cc-467c-8067-97e0141e0f83)

When having a wider window it is correctly formatted:
![softwrap_fullscren](https://github.com/neovim/neovim/assets/121407246/c4e94325-efbe-41aa-b836-423b86837c47)

**I assume that Neovim want to write a table row always in one visible row, when using soft wrap (`vim.g.man_hardwrap = 0`), which leads to this strange formatting.**

## Steps to reproduce

1. open a window in your terminal emulator with under 180 columns.
2. Open a man page in neovim with soft wrap, e. g.: `nvim --clean "+lua vim.g.man_hardwrap = 0" "+hide Man systemd.unit"`. The behavior is the same then opening the man page inside of Neovim (`:hide Man systemd.unit`).
3. Scroll down to chapter _UNIT FILE LOAD PATH_ and look at _Table 2.  Load path when running in user mode (--user)._

## Expected behavior

**TL;DR**: I'd expect that Neovim in soft wrap mode also creates multi line cells.

When using hard wrap Neovim does format the table into multiple rows. So Neovim seem to have this capability somewhere and it should be possible that tables in soft wrap mode also get multi line cells.

Initial open with hard wrap in a narrow window:
![hardwrap_splitscreen](https://github.com/neovim/neovim/assets/121407246/7dcc09bc-53fe-4d9d-9619-34f91a5fd370)

Initial open with hard wrap in a wide window:
![hardwrap_fullscren](https://github.com/neovim/neovim/assets/121407246/6439f582-1486-41b9-9e23-a0e1ef46f2cb)


### Related Issues and Differentiation

This was previously discussed in other issues:

- https://github.com/neovim/neovim/issues/10748  
- https://github.com/neovim/neovim/issues/11436

Those issues where about setting the default behavior back to hard wrap. In contrast to these issues I'd expect Neovim to correctly format wide tables into multi line cells, also in soft wrap mode.


### Possible Solutions

As described in the _Problem_ section hard wrap is no good solution for a window, which regularly resized.

- In hard wrap mode the tables are much smaller than the available lines. Maybe it would be a solution to format the tables like in hard wrap mode also in soft wrap mode. This wouldn't erase the problem in its whole, but could minimize it.
- Also enable multi line cells when using soft wrap. I assume that this needs to regenerate the complete table at a resize event.


## Environment

### Neovim version (nvim -v)

`NVIM v0.10.0` and confirmed in `NVIM v0.11.0-dev-200+g9afa1fd35`

### Vim (not Nvim) behaves the same?

does not have this feature.

### Operating system/version

Arch Linux

### Terminal name/version

kitty 0.35.1

### $TERM environment variable

xterm-kitty

### Installation

system package manager (`pacman -S neovim`)