Extra Characters after Running VIM

Hello,

I face the same issue and still can’t solve it.
This does not happen just after I start sessions.
I don’t see it in Terminal.app.

Best regards,

Hello,

I found a reproducible condition which causes the Copy & Paste problem. Just after starting a session, pasting by "command+v" works well, but once I launch the vi editor and then close it, the paste command outputs a copied string with uncalledfor characters.

For example,
copied string: free
pasted string: 00~free01~

I would appreciated it if this bug could be fixed.

Best regards,

Koji

Hi Koji, thank you so much for the steps to reproduce. Though I still could not reproduce the issue, but according to your report, I just found a potential problem in the code.

I'll send you a personal message includes a revised binary for verifying.

Yang

Thank you for your quick response. I'm looking forward to hearing form you again.
Have a good day.

HI Koji, what's the version of vi your were running?

It's version 8.0.1365.
But, I tried another version, 8.1.2292, on MacOS Catarina. It seems that the copy & paste problem does not happen.

Koji, thank you very much for the information. I searched vim changelog, and found this:

Patch 8.1.1198
Problem: Bracketed paste may remain active after Vim exists, because the terminal emulator restores the setting.
Solution: Set/reset bracketed paste mode before setting the terminal mode. (closes #3579)
Files: src/term.c

This issue happens with vim < 8.1.1198.

Pseudo terminal actual has two screen buffer: the primary screen buffer (used by bash, zsh etc.) and alternate screen buffer (used by vim, nano etc.), they have their own bracketed paste mode. The correct workflow to launch vim should be:

  1. Switch to alternate screen buffer
  2. Set bracketed paste mode
  3. Do some editing...
  4. Finished with :q
  5. Reset bracketed paste mode
  6. Switch back to primary screen buffer (bash or zsh)

But vim < 8.1.1198 does the first two steps wrong way round:

  1. Set bracketed paste mode
  2. Switch to alternate screen buffer
  3. Do some editing...
  4. Finished with :q
  5. Reset bracketed paste mode
  6. Switch back to primary screen buffer (bash or zsh)

It actually set the bracketed paste mode in primary screen buffer (bash/zsh), not alternate screen buffer (vim).

Terminal.app shares bracketed paste mode between primary and alternate screen buffers, so that not a problem for it.

But Core Shell internal mechanisms is quite different from system Terminal.app. It has separate bracketed paste modes (and lots of other modes like auto wrap and reverse video etc.) for primary and alternate screen buffers.

The benefit of separate modes is: if vim (or arbitrary applications which use alternate screen buffer) crashed (exit abnormally), the primary screen buffer won't be polluted, and vice versa.

Since it's a bug of vim, and has been fixed already, I'm not going to change the behavior of set/unset bracketed paste mode.

Is it possible for you to upgrade your vim?

Thank you again,

Yang

Hello, Yang.

Thank you very much for checking the details and explaining the results.
I updated the vim to the newest version 8.2.1200 on my remote server and confirmed that vim does not cause the copy & pate problem.

I would like to express my appreciation for the speed in your work.
I will continue to use Core Shell as one of my favorite tools.

Have a good day.
Koji

Koji, thank you very much for supporting our work, please let me know whenever you need assistance :smiley:

Kindly Regards,

Yang