sjl / vitality.vim

Make Vim play nicely with iTerm 2 and tmux.
http://github.com/sjl/vitality.vim
MIT License
320 stars 30 forks source link

some vim movements cause strange content shift #3

Open mydimension opened 12 years ago

mydimension commented 12 years ago

one poignant example is doing 'cw'

seems to only effect buffers that represent a file. i can't duplicate this in unnamed buffers (makes sense as there is nothing to autosave, perhaps?)

I'll use JSON.pm (v2.53) as an example:

Starting state (cursor position represented as [X]):

use base qw(Exporter);
@[J]SON::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_json);                                                                                                                                                            

BEGIN {

do a 'cw' to change the word "JSON", i end up in this state:

use base qw(Exporter);
@JSON::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_json);                                                                                                                                                            
[@]::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_json);    
BEGIN {

interestingly, if I move around (i.e. PgDn then PgUp) everything appears normal.

also, the behavior does not happen if I defocus/refocus iterm2 prior to the 'cw' command but after opening the file.

at all times, defocusing iterm2 gives the following in the status line "No matching autocommands"

sjl commented 12 years ago

Okay, part one of this is to silence the harmless "no matching autocommands" error. I'm making that a second ticket.

vectorstorm commented 12 years ago

I'm getting the same issue as mydimension. For me, it happens only when running through tmux, not when running normally in iTerm2.

It's most consistent when I press 'x' immediately after opening a file. It's interesting to note that when it happens, in addition to the changes that mydimension quoted, my (vim default) status line changes from:

JSON.pm                                                             :b1[perl] 3,0-1 All
"JSON.pm" 4L, 271C

to:

JSON.pm                                                               :b1[perl] 2,2 All
"JSON.pm[+]L, 271C                                                 :b1[perl][+        d
l                                                                             

It looks like the status line has made just barely enough space to tell me I used the 'x' command, and then printed 'dl' instead, which made the terminal scroll up one line unexpectedly. Similarly, if I use 'X', it prints 'dh', split across the two lines, producing the same apparently-scrolled terminal screen.

I've checked :map, and no, I haven't mapped x to dl, or anything weird like that. And if I use cursor keys to move the cursor around a little before editing, the problem usually doesn't happen.

I've spent the last hour or so making a reproducible test case, and I've found that the minimum setup required for me to get this behaviour is a .vimrc containing nothing but the following lines:

set showcmd
if exists('$TMUX')
    let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
    let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
endif

'showcmd' is required, in addition to both t_SI and t_EI. If any of these three are set differently, then the bad behaviour doesn't happen for me. But with all three set this way, if I edit this .vimrc from inside tmux, and then press 'x' immediately after opening the file, I get the odd screen content scrolling happening almost every time.

(So for the time being, I'm making do without 'showcmd'). Not quite sure what would cause this misbehaviour, but I thought I'd include the steps I took here, just in case they meant more to somebody else.

aaronjensen commented 12 years ago

see #8 for an alternative solution that doesn't require vitality.vim