This one is driving me mad. I'm using XTerm(330) and the latest vim 8.0.1365 (on FreeBSD).

Sometimes, not always, about 1 in 5, when I open a file with vim, a funny line is inserted above line 1. After a lot of head scratching, I realized it is the last line I deleted in a previous session. In other words, it looks like ""P (paste the " register) is run.

After some more investigation, I found this only happens when I have *sunKeyboard: true set in the XTerm resources, and when I use a rendered font, such as -fa "DejaVu Sans Mono:size=24". (I told you it was strange, didn't I?). I have no .vimrc and no .vim directory, to avoid any plugin playing tricks on me.

I can reproduce the effect somewhat with the following commands:

rm -f .viminfo; echo inserted >bar; echo x >baz
vim -c d -c wq bar
echo '*sunKeyboard: true' > XTerm
for i in 1 2 3 4 5 6; do
   xterm -fa "DejaVu Sans Mono:size=24" -e vim baz

This will create the necessary files, place inserted in the " register and invoke vim a few times. If you see a one line file with x in the first line, all is fine; enter q for the next invocation. If however you see


you have reproduced the problem. Note also that the last character of line 1 has been replaced by 2. This seems to come from the . register. Here are the registers:

--- Registers ---
""   inserted^J
"1   inserted^J
".   2
"%   baz
  • Trying the script several times, can you reproduce the problem? Be sure to move .vimrc and .vim temporarily out of the way.
  • If so, can you tell me what is going on here?
  • Any suggestions how to get to the bottom of this?


Looks like I'm not the only one: https://github.com/vim/vim/issues/2238

  • Does either set t_RS= or set t_SH= in your vimrc work?
    – Mass
    Dec 13, 2017 at 21:18
  • @Mass Yes, either of them works, i.e. no more magic line insertion. With these entries the :reg command no longer shows the ". contents.
    – Jens
    Dec 13, 2017 at 21:23
  • Have you checked if github.com/vim/vim/pull/2126 fixes your issue? What exactly is the output of :echo v:termresponse? Feb 14, 2018 at 20:36
  • @ChristianBrabandt The output is ^[[>19;331;0c. The github page is a twisty little maze I have no idea how to glean information from. Near the bottom it says "closed", but I can't seem to find a patch number, such as "fixed in 8.0.####". Thanks for taking the time to comment!
    – Jens
    Feb 14, 2018 at 21:00

1 Answer 1


When vim starts up, it interrogates your terminal emulator, which responds with terminal codes. vim usually captures this in v:termresponse. Sometimes, however, the codes get through and they frequently look like vim commands and cause unintended behavior.

Two of the options which controls what vim sends seem to cause many people issues:

t_RS    request terminal cursor style           *t_RS* *'t_RS'*
t_SH    set cursor shape                        *t_SH* *'t_SH'*

These were added recently to allow vim to set the cursor shape and determine the default terminal cursor. Setting either of these to empty (set t_SH= or set t_RS=) causes vim to skip the check. It is the response from your terminal which is causing the problem.

This is most likely a vim bug, because it should work by default in xterm. Besides setting these options to empty, I suggest,

  • updating to the most recent vim version
  • report the bug (see :h bugs), carefully noting your platform and terminal emulator, the precise behavior seen, and the value of v:termresponse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.