base46 icon indicating copy to clipboard operation
base46 copied to clipboard

Lines in man pages break prematurely

Open lingling9000 opened this issue 1 year ago • 3 comments

Describe the bug Lines in man pages break prematurely. This reason seem to be the additional padding on the left.

This does not happen in Neovim without a config. So it need to come somewhere from NvChad, but I couldn't figure out, which option sets that additional padding.

To Reproduce Steps to reproduce the behavior:

  1. Install NvChad/starter
  2. export MANPAGER='nvim +Man!'
  3. man namespaces

This does also happen when open the man pages from inside Neovim with :Man namespaces or the respective Telescope picker.

Expected behavior Lines should not prematurely break in man pages. I can imagine two solutions:

  1. Disable the padding on the left when filetype man is detected. I don't know how, because I don't know how and where the padding is set.
  2. Enable soft_wrapping for man pages with vim.g.man_hardwrap=0. See :h man for details. This also enables the reformatting of the content when the window is resized. I recommend to set this option as default.

Screenshots man page with no config: nvim_manpage_noconfig

man page with unmodified NvChad starter config. I marked the first 4 bad linebreaks red, but when you look into the chapter The namespaces API you can see that nearly every line has a prematurely linebreak: nvim_manpage_nvchad

Desktop (please complete the following information):

  • kitty 0.35.1, but I could replicate the same behavior in other terminals, e. g. Alacritty.
  • NVIM v0.10.0

Additional context It is important to note that there are differences in opening the man page by the man command or from inside Neovim. When using the man command on the shell the man page is pre-formatted with groff and the soft_wrapping setting is useless. :h man tells the workaround to export MANWIDTH=999, but this will result in a broken title bar and therefore I won't recommend that. A better solution is to redefine the man command in the shell (as recommended in :h man):

man() {
    nvim "+hide Man $1"
}

lingling9000 avatar Jun 08 '24 12:06 lingling9000

I used soft wrap (vim.g.man_hardwrap = 0) and noticed a problem with the formatting of wide tables in e. g. systemd.unit(5):

softwrap_splitcreen

But is is not an unknown issue and they previously set hard wrap to be more fool prove (https://github.com/neovim/neovim/issues/10748, https://github.com/neovim/neovim/issues/11436). Nevertheless I opened an issue, because I would expect that Neovim would be able to create multi line cells in man pages, even when using soft wrap: https://github.com/neovim/neovim/issues/29249.

In view of the facts I need to withdraw my recommendation to set soft wrap as default, for now. Therefore I think the best solution for NvChad would be to disable the left padding when filetype man is detected.

Another solution, would be to use hard wrap and subtract the padding from the terminal columns and set this as MANWIDTH environment variable. When I understand it right, they've done something similar in the past:

lingling9000 avatar Jun 09 '24 11:06 lingling9000

does this happen with other neovim configs?

siduck avatar Jun 27 '24 03:06 siduck

I tested it with LazyVim.

Soft Wrap

They seem to default to soft wrap. When testing with systemd.unit(5) I can also see that broken tables. But as I pointed out in the previous comment, this is an upstream Neovim bug and not a problem with NvChad/base46.

Hard Wrap

I've done following steps to test hard wrap in LazyVim:

  • :let g:man_hardwrap=1
  • :Man namespaces
  • Result:

lazy_vim_hardwrap_2

They also have a padding on the right side and therefore break lines prematurely.

lingling9000 avatar Jun 28 '24 15:06 lingling9000

Temporary fix: add this to your bashrc

# shrink Man page by size of  padding
export MANWIDTH=$(( $(tput cols) - 2 ))
# resize the environent-variable when window is resized
trap 'export MANWIDTH=$(( $(tput cols) - 2 ))' WINCH

or set vim.opt.signcolumn = "no"

Dragit avatar Nov 29 '24 21:11 Dragit


vim.api.nvim_create_autocmd("FileType", {
  pattern = "man",
  command = "setlocal signcolumn=no",
})

siduck avatar Nov 30 '24 00:11 siduck