Vim screen corruption with screen/tmux and matchparen.vim

I’ve been experiencing an irritating bug for a few weeks and I finally eliminated it by disabling matchparen.vim

The bug happens when I’m using vim in an ssh session (to a Linux machine) with GNU Screen or tmux (on the server) in iTerm2.app or Terminal.app on Mac OS X and editing PHP code. If I type “require dirname(__FILE__) .“, then after typing the closing parenthesis, the screen gets corrupted such that it looks like I typed “require dirnam((__FILE_))” (missing “e”). Hitting Control-L refreshes the screen of course, but it’s irritating nonetheless.

Yesterday, I got the bug to disappear by putting this in my ~/.vimrc.local (I’m using Janus):

" vim's parenthesis highlighting causes screen corruption when vim is running
" inside GNU screen or tmux?
let loaded_matchparen = 1

I don’t know if this is a bug in matchparen.vim or something else.

If I type slowly, it looks like after typing the closing parenthesis, both the opening and closing parenthesis are highlighted correctly. Things go haywire after typing a space after the closing parenthesis. It looks like it’s attempting to replace the highlighted open parenthesis with a normal parenthesis but it does it one cursor position to the left, resulting in the “e” in dirname getting overwritten with a parenthesis and the highlighted open parenthesis is still present next to it.

Here’s a screenshot: http://cl.ly/1E1I2X0t3e1F3c3F2I2J

If I understood more clearly what the problem is, then I’d try to fix it and submit a patch, but I’m not very knowledgable about terminal issues. If someone points me in the right direction, I might be able to come up with a patch…

I’ll be posting this to the vim_dev mailing list as well.

4 thoughts on “Vim screen corruption with screen/tmux and matchparen.vim

  1. OK, I played around a bit more and I’ve reduced this to the smallest
    possible case.

    The root of the problem appears to be that Janus sets listchars with a
    UTF-8 encoded Unicode character, namely U+00B7 or “MIDDLE DOT” which
    is encoded as “0xc2 0xb7” in UTF-8.

    marca@web01:/home/marca$ cat ~/.vimrc 
    set encoding=utf-8 
    set list listchars=tab:\ \ ,trail:· 
    
    marca@web01:/home/marca$ hexdump -C ~/.vimrc 
    00000000  73 65 74 20 65 6e 63 6f  64 69 6e 67 3d 75 74 66  |set 
    encoding=utf| 
    00000010  2d 38 0a 73 65 74 20 6c  69 73 74 20 6c 69 73 74  |-8.set 
    list list| 
    00000020  63 68 61 72 73 3d 74 61  62 3a 5c 20 5c 20 2c 74  |chars=tab: 
    \ \ ,t| 
    00000030  72 61 69 6c 3a c2 b7 0a                           |rail:...| 
    00000038 
    
    marca@web01:/home/marca$ python 
    >>> middle_dot = u'\xb7' 
    >>> print middle_dot.encode('utf-8') 
    · 
    >>> middle_dot.encode('utf-8') 
    '\xc2\xb7' 
    

    My guess at this point would be that matchparen.vim has some code in
    it that is not multi-byte aware.

  2. Thank you for posting this! I’ve been having constant frustration with text corruption using tmux and vim for months, and it was my UTF-8 listchars that is apparently the trouble. I was getting to the point where I couldn’t trust anything outside of mvim when on my mac…much obliged!

  3. Hey Aaron,

    I’m glad to hear that it helped someone besides myself! Thanks for taking the time to write!

    Marc

Leave a Reply

Your email address will not be published. Required fields are marked *