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.

  • instead of having the wrong number of columns, maybe it's the number of lines that is not correct (the "set ruler" is especially hinting to that). Exit vim, and see the values of COLUMNS and LINES (or COLS and ROWS, depending on the shell) are indeed what your terminal really can display. if not you can re-set them before launching vim: COLUMNS=20 LINES=30 vim (on the same line, meaning "during the command invocation, those variables will have that value, and get back to their initial values after") Jan 2, 2013 at 18:22
  • I don't think I understand completely. I echoed "$COLUMNS" and "$LINES" and both were correct. I also checked lines within Vim and they were correct. Reading "man vim" I don't see how to specify columns and rows. Also, I just noticed that "less" is wrapping text before the end of the window. So maybe it is something with bash? I just added this to my original post. Jan 2, 2013 at 19:10
  • Oh, I do see what you meant. You were recommending that I set $COLUMNS and $LINES in bash. But they are correct. Jan 2, 2013 at 19:23
  • I swear I saw something like that a some time ago here or on SO. The problem was that mouse clicking didn't work past a specific column.
    – romainl
    Jan 2, 2013 at 19:31
  • $TERM is xterm-color or xterm-256color?
    – romainl
    Jan 2, 2013 at 19:51

2 Answers 2


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.

  • you should now validate your answer :) Jan 3, 2013 at 9:52
  • Thanks Olivier, I tried to but it won't let me until tomorrow! Jan 3, 2013 at 16:25

I had a tricky :highlight command in my .vimrc that caused this problem which makes vi unusable. You can eliminate/confirm this by starting vi with no config.

First exit ssh session & then logon to get a clean shell then :-

vi -u NONE -U NONE -N file.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .