-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
potential issue with xterm-bracketed paste and pasting long string: #13398
Comments
I ran your command and pasted from Normal mode, got some blank lines. No extra file in
( Trying Pasting in Pasting in an Ex command line was pretty similar.
Could the long string be causing a problem with an internal buffer (overrunning the length or something)? |
Did you try to paste using |
Interesting. I did not use shift+insert (I'd have to look up how to input that on my keyboard), but I'm pretty sure that pasting with Command+v in the past has been bracketed because it acts like |
I cannot reproduce with Vim 9.0.2048 in gnome-terminal, after copying with Curiously, the pasted text starts with ^C (hex 03) if I use vim's middle-click handling, but some weird unicode ETX character (hex 2403) if I use shift-middle click. In either case the :,!touch /tmp/oh ends up in the buffer and my /tmp doesn't get any new files. Pasting with shift+insert results the same as shift-middle click. Pasting with Ctrl+Shift+V uses the clipboard instead of the selection and thus requires I get the same results both in normal mode and in insert mode. My paste settings are
|
This is likely a terminal specific behaviour, gnome-terminal is replacing the ^C (ASCII ETX) with U+2403 which is a symbol that represents that ASCII character. In an actual xterm (not something claiming compatibility with it via
i.e. adding ETX to the default. The quick way to test this for xterm is to run and compare:
With that resource set via The proper fix for this issue is likely making terminals that support bracketed paste mode also filter out (more) non-whitespace control characters. This affects xterm as shown and some other terminals; I am aware of at least kitty and the author is making some changes there. Basically ^C having an effect within bracketed paste mode is somewhat surprising and it would be good defence-in-depth for Vim to just not accept ^C within bracketed paste mode. (I've only looked at ^C in detail, potentially there could be a further similar issue with Escape itself, this won't apply to xterm as disallowedPasteControls obviously filters Escape by default but it appears some terminals only filter the data pasted within bracketed mode paste for the exact bracketed paste end sequence.) |
correction: all this was caused by the That's easily reproducible with xterm in its default config, without any space padding -- and not only with
And there's also the problem of insert mode mappings, which IMHO should not be interpreted in the pasted text. And that's not fixable in the terminal emulator, because the mapped keys may not be control characters at all. Consider the difference between If bracketed-mode were working as promised (= insert the pasted text "literally"), |
Are you sure you have been using bracketedpaste mode in xterm? Because mappings are intentionally disabled in bracketed paste mode (and the paste option is also set, so indenting etc shouldn't happen): Lines 4397 to 4402 in 50f3ec2
|
Yes. I have a script(1)-like program which logs both the input and the output. Looks like vim is somehow reversing the enable and disable bracketed-paste escapes. See the attached picture of the log -- yellow is the input, blue is the output. See how bash correctly enables bracketed-paste mode just before the prompt with My system is Debian 12, and vim is just compiled from github. The terminal the log was generated on is |
I think I got it. vim enables the bracketed mode globally upon starting, but since 48c9f3b, it turns it off when entering insert mode if So the morality is: Maybe that's even documented somewhere, sorry for the noise if true ;-) |
I didn't see any pointers to bracketed paste being disabled when esckeys is off (only to modifyOtherKeys) |
related: #13398 Signed-off-by: Christian Brabandt <cb@256bit.org>
@k-takata @benknoble I added a few pointers to the documentation. |
Ctrl-C is handled specifically and removed from the input buffer. However, when bracketed paste mode is active, we should not handle it like this but just like a normal character Not sure, this is the best way to handle it. related: vim#13398 Signed-off-by: Christian Brabandt <cb@256bit.org>
@dgl I did check this and made the following patch: chrisbra@d857ac0 I am not sure this is the best way to handle it. Plus, I think one loses the possibility to break-out of paste-mode using Ctrl-C in case something goes wrong. Which means, the user may not be able to quit at all. So not sure. BTW: I don't know which buffer fills up too much :( |
That's not a matter of filling up any buffer, but of causing a delay/reschedule, forcing vim to reenter its main loop between the
then press middle-click in xterm. (that |
I tried the patch but there's some issues, like the bracketed paste escape sequences can end up not just at the start of the buffer. It also needs a partial revert of fdd7155 and potentially 98a336d, although those clearly show ^C interrupting is a good idea in some cases... Vim puts xterm into "modifyOtherKeys" mode, so actually Vim can tell the difference between a user pressing ^C and a ^C being pasted. (The user pressing it sends an escape sequence, as part of a paste it is a literal ^C). I tried the obvious key_protocol_enabled() after making it usable in other places, but that doesn't seem to work, it would be nice as this could avoid needing knowledge about bracketed paste mode. This may be moot, as xterm 388 now has a new default for disallowPasteControls that filters all stty special characters see, ThomasDickey/xterm-snapshots@18c5678 -- although the behaviour on other terminals may still leave something to be desired, most terminals copy features from xterm, so we can just point them at that ;-) |
When a key protocol is in use ^C will be sent as an escape sequence, but a raw ^C can be sent when pasting data. Pass this through, so a ^C can be pasted and won't result in exiting insert mode. Many terminals will strip control characters in paste data (and xterm will strip ^C since version 388), but this provides some defense in depth if users change settings like xterm's allowPasteControls. Fixes vim#13398 Signed-off-by: David Leadbeater <dgl@dgl.cx>
Embarrassingly I tested it on an ancient version of xterm I had sitting around; it needs at least 377. I think this could work: 832ec17 Will need to test that on a few terminals, but it seems to work on xterm >=377 (and <388). Edited to add: Also tested that commit with Kitty (before kovidgoyal/kitty@defa2e2, need to test if this also protects "paste anyway" after that) and it stops command execution being possible (in testing this I had to modify the padding size to 20k to get Kitty to run commands on Linux, before the Vim fix). |
Thanks, let me include this to make bracketed paste mode more robust in Vim. I think this makes sense (even so it seems terminals are going to fix it on their side anyhow). |
Steps to reproduce
I have been told, that the following overcomes the xterm-bracketed paste modes and causes it to create the file
/tmp/oh
which should not happen. Notice, it only hapens with the long random string of spaces that is appended.I am currently not sure why this is happening, it needs to further investigated.
Run the following command:
(use xsel or xclip to copy into Linux X11 clipboard/primary selection) and paste into an xterm terminal (to make sure we are using xterm-bracketed paste mode, check the
:set t_PS? t_PE? t_BD? t_BE?
output).when pasting from insert mode, it will create the file
/tmp/oh
which shouldn't happen.Expected behaviour
buffer content should be pasted into buffer (or into the command line (because of the escape char at the beginning of the string), but shouldn't be executed.
Version of Vim
9.0.2054
Environment
linux
xterm
bash/zsh
Logs and stack traces
No response
The text was updated successfully, but these errors were encountered: