Mac – Vim text messed up on remote server

bashdebianemacsterminal.appvim

I often work on remote servers. There is one server that seems to get "confused" about the number of available columns (my best guess), but only when working in Vim (not bash). Specifically, when I open a file with long lines, everything looks normal at first. But as I move around, the text get jumbled up. The cursor will appear as though it's over a certain word, but I'm actually on a different line. I can tell because if I search for the word the cursor is covering, a word from another line suddenly appears under my cursor. Also, some of the text appear to be wrapping to the next line (even though I have "set nowrap"). And it wraps much sooner than the window would require.

If I perform "ls" on the command line, text extends to the end of the window. So I think it's Vim specific.

What I've checked:
1. I've checked that $TERM matches the $TERM on my local machine (thinking there was some miscommunication there). Both are "xterm-color".
2. I've checked that Vim hasn't set some odd number of columns (verbose set columns?). The returned value matches the width of my window.
3. I've done a lot of googling and couldn't find anything related.

I appreciate any help. Let me know how I can clarify.

My local machine is Mac OS X Mountain Lion. Remote server is Debian (Squeeze). Remote Vim is 7.2.

EDIT-1:
I don't know if the following are related, but here are a few more symptoms:
1. If I split the screen within Vim, the file info lines between them get jumbled up (must be related, I think)
2. "set ruler" does not work

EDIT-2:
I just realized that "less" is wrapping text too early (way before the end of the window) and at the exact same spot Vim is attempting to. So I'm guessing it actually is related to bash somehow. The only difference with "less" is that the lines do not get messed up like they do in Vim.

EDIT-3: This is all probably obvious now, and I should have checked other editors earlier, but naturally emacs has the same issues as Vim. Is this a bash issue? A Term issue?

EDIT-4: I just tried accessing the same files remotely using iTerm (instead of Terminal.app) and it is working perfectly. I don't know what to make of that. In a sense my problem is solved, but I would love to understand what is going on if anyone can shed some light.

Best Answer

I'm not certain exactly what was going on or what fixed it but, as mentioned above, I accessed the remote file using iTerm (instead of Termanal.app) and everything formatted as expected. Based on this, I assumed something was awry between Terminal.app and the remote server. User romainl suggested I explicitly set $TERM to xterm-256color in my ~/.bashrc (set TERM=xterm-256color) on the remote server and try again with Terminal.app. When I did that the text formatted correctly, though with incorrect sytax highlighting. I then removed the previously mentioned line from my ~/.bashrc on the remote server, closed the session and began anew. This time everything worked as expected. It may have simply been that Terminal.app was being buggy.

Thanks again to everyone who volunteered their knowledge.

Related Question