29 Dec 2010 10:39
vim -w or -W records K_SPECIAL sequence from xterm version string in script
Josh Triplett <josh <at> joshtriplett.org>
2010-12-29 09:39:15 GMT
2010-12-29 09:39:15 GMT
vim -w or -W records all the keystrokes entered in Vim. If running on an xterm or another terminal that supports requesting the terminal version, vim will do so, and process the resulting version response to set a few options. In the process of doing so, it ends up recording three extra bytes at the beginning of the script file: /tmp$ vim -u /dev/null -N -W foo /tmp$ hd foo 00000000 80 fd 35 5a 5a |..5ZZ| 00000005 This affected quite a few people playing on vimgolf.com. After some adventures through vim's source, I think I've tracked down exactly what happens to cause the problem: - Vim asks the terminal for its version string when it starts, in the may_req_termresponse function, by sending the kPRV string from the terminfo record, and then calling vpeekc_nomap. - That reads the response from stdin into typebuf, and eventually ends up in check_termcode, which handles terminal escape sequences. - check_termcode finds the version response, and if it manages to extract an xterm version number, it sets various features based on that version number. - check_termcode then translates the escape sequence into the key_name array as KS_EXTRA and KE_IGNORE, which match the second and third bytes of the escape sequence.(Continue reading)
RSS Feed