9

I have two remote servers:

Server 1: Linux 2.6.18-238.12.1.el5PAE i686 / VIM - Vi IMproved - version 7.0.237
Server 2: Linux 2.6.18-338.19.1.el5.lve0.8.36 x86_64 / VIM - Vi IMproved version 7.0.237

When I ssh into Server 2 and use vim to edit a php or .htaccess file it has beautiful color highlighting. Below is the /etc/vimrc file on that server.

When I ssh into Server 1, no color shows up. I tried copying the code below into my ~/.vimrc file on Server 1, but the color syntax is not working. The other features (like set nocompatible) are working, but not the colors.

Why is the color not working on the Server 1, and how can I test and fix it? tput colors on both terminals returns 8. I tried :syntax on and :syntax enable but that's not helping either.

------------------------------------------------------------

Contents of /etc/vimrc file:

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=utf-8,latin1
endif

set nocompatible    " Use Vim defaults (much better!)
set bs=indent,eol,start     " allow backspacing over everything in insert mode
"set ai         " always set autoindenting on
"set backup     " keep a backup file
set viminfo='20,\"50    " read/write a .viminfo file, don't store more
            " than 50 lines of registers
set history=50      " keep 50 lines of command line history
set ruler       " show the cursor position all the time

" Only do this part when compiled with support for autocommands
if has("autocmd")
  augroup redhat
    " In text files, always limit the width of text to 78 characters
    autocmd BufRead *.txt set tw=78
    " When editing a file, always jump to the last cursor position
    autocmd BufReadPost *
    \ if line("'\"") > 0 && line ("'\"") <= line("$") |
    \   exe "normal! g'\"" |
    \ endif
  augroup END
endif

if has("cscope") && filereadable("/usr/bin/cscope")
   set csprg=/usr/bin/cscope
   set csto=0
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
      cs add cscope.out
   " else add database pointed to by environment
   elseif $CSCOPE_DB != ""
      cs add $CSCOPE_DB
   endif
   set csverb
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

if &term=="xterm"
     set t_Co=8
     set t_Sb=%dm
     set t_Sf=%dm
endif

:version output

VIM - Vi IMproved 7.0 (2006 May 7, compiled Aug  4 2010 07:21:18)
Included patches: 1, 3-4, 7-9, 11, 13-17, 19-26, 29-31, 34-44, 47, 50-56, 58-64, 66-73, 75, 77-92, 94-107, 109, 202, 234-237
Compiled by <bugzilla@redhat.com>
Tiny version without GUI.  Features included (+) or not (-):
-arabic -autocmd -balloon_eval -browse +builtin_terms -byte_offset -cindent -clientserver -clipboard -cmdline_compl -cmdline_hist -cmdline_info -comments -cryptv -cscope -cursorshape -dialog -diff -digraphs -dnd -ebcdic -emacs_tags -eval -ex_extra -extra_search -farsi
-file_in_path -find_in_path -folding -footer +fork() -gettext -hangul_input +iconv -insert_expand -jumplist -keymap -langmap -libcall -linebreak -lispindent -listcmds -localmap -menu -mksession -modify_fname -mouse -mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm
-mouse_xterm +multi_byte -multi_lang -mzscheme -netbeans_intg -osfiletype -path_extra -perl -printer -profile -python -quickfix -reltime -rightleft -ruby -scrollbind -signs -smartindent -sniff -statusline -sun_workshop -syntax -tag_binary -tag_old_static -tag_any_white
 -tcl +terminfo -termresponse -textobjects -title -toolbar -user_commands -vertsplit -virtualedit -visual -viminfo -vreplace +wildignore -wildmenu -windows +writebackup -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save
   system vimrc file: "/etc/virc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation:
gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2
Linking: gcc   -L/usr/local/lib -o vim       -lselinux -ltermcap -lacl
  • Open your PHP file, type :set term, :set filetype and give us the result. – quanta Aug 26 '11 at 2:11
  • term=xterm, E519:Option not supported: filetype – cwd Aug 26 '11 at 2:21
12

I suspect that you have an alias vim=vi in ~/.bashrc. Try this to run 'real' command, not alias:

\vim /path/to/php/file

Looks like your are running CentOS. Make sure that you installed vim-enhanced package:

rpm -qa | grep vim
vim-minimal-7.0.109-4.el5_2.4z
vim-enhanced-7.0.109-7.el5
vim-common-7.0.109-7.el5
  • i will install the enhanced version and see if that makes a difference. thanks for looking into this one. – cwd Aug 26 '11 at 2:51
4

You can tell by your version output of vim that it's vim-tiny and its' not compiled with the -syntax option.

Also put export TERM=xterm-256color in your bashrc to get the full benefit...

4

You can also use sshfs to mount the resource so that your local vim is used to edit these files.

Vim can also edit remote files. The beauty of this is that you can then edit in the comfort of your own customized and familiar vim configuration.

vi scp://username@example.com/path/to/file

0

There is a specific case where if your client terminal doesn't set a color TERM but instead sets COLORTERM. Do this:

On your client machine, add SendEnv COLORTERM into /etc/ssh/ssh_config, and on the server, add AcceptEnv COLORTERM into /etc/ssh/sshd_config.

Reload sshd (service sshd reload) and reconnect.

If your server is CentOS/RHEL and has /etc/profile/256term.sh (provided by the package initscripts), which mine did by default, this should automatically set TERM to xterm-256color, enable color in bash (ls ...) and enable color in vim.

As already pointed out by quanta if you only have vi, install vim-enhanced.

I'm not sure if this is required if your client terminal already sets a color TERM. I had to do this to work around Terminator having a hardcoded TERM=xterm. gnome-terminal on ubuntu does have a default TERM xterm-256color, so color may work without needing Send/AcceptEnv in ssh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.