I've been enjoying the Termdebug feature, but one thing has been nagging me, which that lines are wrapped by inserting newlines in the terminal's output, instead of letting vim handle the wrapping. This has several drawbacks:
Both bash and gdb support not wrapping their output, through a set width 0 option in gdb, and setterm --linewrap off (from the util-linux package, so this is probably wider than just bash).
With these options enabled, switching a terminal's output to normal mode causes non-terminal-wrapped lines appear as expected, wrapped by vim to whatever the current window width is. However, :set wrap does not seem to do anything in terminal mode.
Would it be possible to wrap lines in an active terminal output?
That way, we could enable wrapping whenever we detect that wrapping can be disabled in what the :terminal is running (potentially as a vimrc option). This would make the :terminal option much more useful IMHO.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
Yes, the same happens with a normal terminal. I just thought vim could handle the line wrapping instead of the terminal?
The reason this is especially annoying in vim, is that switching from terminal to normal mode resizes the window, thus causing every full line to wrap with only a couple of characters after the line break.
Other work-arounds could be to force the terminal to wrap lines a little earlier to account for switching to normal mode, or to allow line numbers in terminal mode so the window won't resize.
it might be silly, but have you checked setting the $COLUMNS environment variable to a smaller size?
—
+1 on this, as I often resize the same Vim window (depending on where I SSH from). This becomes pretty comical (and unwieldy) if I had a command running as I'm resizing the window (connecting to a tmux session from a smaller screen often forces rightmost window to be of width 1):
$
p
y
t
h
o
n
I still haven't managed to find a workaround to copy multiline strings in vim terminal (normal) mode without it inserting arbitrary newlines for linewraps. I have to bounce back to a normal terminal when I want to do that. Would be amazing if there was some way around it.
+1 on this
Is there an update on this issue ? I have the problem and I still didn't found any good solution.
Please answer my question: Does the same happen when running the command in an xterm (or other terminal emulator)? If yes, then there is nothing that Vim can do, since it's just providing a terminal emulator to run the command in.
I tried by using screen in xterm and gnome-terminal and it works well

It's also better with vim but when I select and paste I have multiple line when I should have one.
In this gif, I start without screen and resize to reproduce the problem. Then, I use screen to show than it's better and I do a copy/paste to show than one line in the terminal is pasted as multiple lines.
I hope it's clear.
Do you think there is a solution?
Yes screen is a good example of what is desirable.
Instead of inserting hard linebreaks in the terminal output to wrap lines (which then breaks functionalities on resize, on copy/paste, etc. and additionally in vim mucks up the display on entering/exiting normal mode in the terminal buffer), it handles line wrapping dynamically, at every resize.
It's only on text input, not with programs drawing in the terminal that this happens, so this block in on_text() seems to be where the automatic wraps after the rightmost column are inserted:
In particular, when switching from terminal to normal mode, showing line numbers causes every line to be 3-4 characters overlength, which wastes 50% of vertical space.
This will fix that, at least. The 6 should be adjusted based on your max scrollback digits and gutter width.
augroup Terminal
autocmd!
autocmd TerminalOpen * execute "set termwinsize=0x" . (winwidth("%")-6)
autocmd VimResized * execute "set termwinsize=0x" . (winwidth("%")-6)
augroup END
#5769 has some more info on why fixing wrapping is hard. Unfortunately, running screen inside vim isn't an option as it prevents using marks or searching through history.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Please answer my question: Does the same happen when running the command in an xterm (or other terminal emulator)? If yes, then there is nothing that Vim can do, since it's just providing a terminal emulator to run the command in.
To clarify, some terminal emulators handle wrapping well.
I understand it’s giving the appearance of being a line wrapping when in fact something more complicated happens in the background. It’s likely no terminal emulator maintains in memory lines that are longer than it’s display columns just so it can wrap them nicely on display − that would be a nightmare just to figure out where to vertically start the screen.
I’ve digged through the Konsole sources, it’s basically any blocks conditioned on _enableReflowLines inside the Screen::resizeImage(lines, cols) function. So they call it « reflowing » the outputs. In short, it consist of:
I see that the inserted line breaks now marked the following lines with continuation = 1 in their lineinfo:
That is probably enough to:
I do not have a clear picture of how the internals of the vim terminal work however, so I can’t quite estimate how much work this is or promise I can whip up a PR at some point.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Thanks @Cimbali for investigation, two years after my comments, this is still a problem I have daily.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Nice catch on the lineinfo - note that the buffer and terminal are distinct: I believe that a few changes to this could easily give an effect equivalent to set termwinsize=0*∞. Just check continuation and reset pos.col here, and then add some % term->tl_cols where the characters are added just below that. That would fix all wrapping in terminal normal mode, make termwinscroll affect lines period (not visual lines), and prevent having to remove newlines all the time.
Then the terminal just needs to manage its own printing (and only on the visible lines), same as Konsole or screen or anything else.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Thanks @Cimbali for investigation, two years after my comments, this is still a problem I have daily.
Me too! I will never stop following this thread and hoping for a solution. Would love to shut up my Tmux using colleagues :)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Thanks @Cimbali for investigation, two years after my comments, this is still a problem I have daily.
Me too! I will never stop following this thread and hoping for a solution. Would love to shut up my Tmux using colleagues :)
And the emacs ones, too 😬
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Konsole (from personal experience − I use it daily), gnome-terminal, screen (both shown by @GCorbel too) handle wrapping of lines correctly
thanks for the explanation. just jumping here, I use iTerm for my Mac and the problem also occurs. any recommended terminal for Mac?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()