How do I get color while editing file trough a ssh session?

1

2

I use cygwin on Windows7 to open a ssh session to my linux box. When I edit a file with vim, I don't have color, only kind of gray bold.

I have colors when I do a ls into my ssh session.

I have also colors when I edit files from a ssh session from my linux box to my linux box.

I modified the shortcut on Window7 to run cygwin in 256 colors, no effect.

Do I need to set an environment variable on my cygwin session ?


Edit:

On Cygwin and On Fedora when "sshed" from Gygwin : TERM=cygwin

Luc M

Posted 2010-11-25T01:03:54.857

Reputation: 192

Maybe. What does echo $TERM report on the Windows machine and on the Linux machine? What terminal do you run ssh in (a Windows console, rxvt, ...)? – Gilles 'SO- stop being evil' – 2010-11-25T01:49:00.260

Are you invoking Vim as "vi" or "vim" on the command line? Many distributions have a stripped down version of Vim installed as "vi" that does not support highlighting, plus a complete version installed as "vim". – Heptite – 2010-11-25T02:10:48.033

@Heptite I use vim my_file – Luc M – 2010-11-25T03:22:40.523

@Gilles Both xterm are set to cygwin by default. I use ssh into a shortcut of cygwin. It's pointed to a bat file that executes bash --login -i. – Luc M – 2010-11-25T05:20:58.000

Answers

1

Maybe the Linux box doesn't have the right data about the cygwin terminal type. You could try using a different terminal on the Windows side: instead of starting cygwin.bat, start c:\path\to\cygwin\bin\rxvt.exe -e c:\path\to\cygwin\bin\bash --login (Cygwin ships with a Windows native version of rxvt). There are alternatives to rxvt (which, in particular, is not Unicode-aware), such as mintty and puttycyg. These alternatives tend to be better for running Cygwin programs in; for Windows console programs, Console2 works better (Cygwin doesn't emulate a Windows console). See also Good Alternative to Cygwin with Copy/Paste?.

Gilles 'SO- stop being evil'

Posted 2010-11-25T01:03:54.857

Reputation: 58 319

That's definitely worth a try, although both Fedora 14 and Ubuntu 10.04 include cygwin in their terminfo databases, so Luc's Fedora box should recognize cygwin as a terminal type. – garyjohn – 2010-11-25T16:25:20.147

@garyjohn: you're right, and if cygwin was not recognized the symptoms would be much worse. I still recommend mintty or puttycyg for cygwin programs anyway. – Gilles 'SO- stop being evil' – 2010-11-25T20:35:41.373

It works! I'll give a try to mintty and puttycyg to get unicode support. Thank you. – Luc M – 2010-11-26T00:57:45.963

0

Try setting syntax on in vim:

:set syntax on

look here:

Check some other file type - e.g. edit a new file "abc.c" and put the C program from the above link. If you don't get syntax coloring, you are probably using some old vim.

If you don't have vim-enhanced installed, install that one, though I have that installed on Fedora 13.

icyrock.com

Posted 2010-11-25T01:03:54.857

Reputation: 4 623

I use the vim version available in yum depot for fedora13. I have syntax color in session from my fedora box. When I set TERM to vt102, the arrows key don't work in vim to recall previous command. – Luc M – 2010-11-25T02:54:28.583

I try setting TERM on cygwin and on Fedora. Niet :-( – Luc M – 2010-11-25T03:00:20.730

Take a look here: http://forums.fedoraforum.org/showthread.php?t=217019. It suggests installing vim-enhanced, so if you only have vim-minimal, try that.

– icyrock.com – 2010-11-25T03:12:41.690

1You don't need to set TERM on the Cygwin box; you may need to set it on the Linux box. Don't set TERM to vt102, however, as that will tell Vim that your terminal doesn't support colors. I just tried connecting to my Linux box from my Cygwin box using both the default Cygwin terminal (which sets TERM=cygwin) and mintty (which sets TERM=xterm) and I get color in Vim just fine, so we should be able to get it to work for you. Please answer Gilles's question above. – garyjohn – 2010-11-25T03:25:01.293

@garyjohn Thanks for a comment, I corrected the answer! – icyrock.com – 2010-11-25T03:29:23.647

1What I do in situations like this is to compare the two environments, compare the two Vim configurations, and examine the differences. When logged in to Linux directly: 1) execute env > env.linux; 2) execute vim --version > version.linux; and 3) execute vim -c 'mkv vimrc.linux' -c q. Do the same when ssh'd from Cygwin, but change "linux" to "cygwin" in the file names. Then run vimdiff on each pair of files to look at the differences. You may need to edit the files to get the variables to line up. – garyjohn – 2010-11-25T04:16:26.137

@garyjohn: Tip: export >env.linux gives you alphabetically sorted output with most shells, it's a bit nicer to look at. – Gilles 'SO- stop being evil' – 2010-11-25T08:34:26.880