Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim "syntax on" does not work

Tags:

vim

vi

opensuse

Here is my .vimrc

  1 syntax on
  2 set ts=4
  3 set number
  4 set smartindent
  5 set shiftwidth=4

However, I tried to edit HelloWorld.java and HelloWorld.c. Both have pure regular black font. No any highlighting!

I also tried :syntax on after the vim is open, but no luck.

\>vim -version
VIM - Vi IMproved 7.3 (2010 Aug 15)

\>cat /etc/*-release
openSUSE 11.4 (x86_64)
VERSION = 11.4
CODENAME = Celadon
like image 756
JackWM Avatar asked Apr 23 '13 22:04

JackWM


2 Answers

When you edit the file, are you using

vim filename

This can matter. In some server configurations, if you do vi filename you get vim, but it's a very stripped down version of vim that is very much like the original vi (which does not, among other things, do syntax coloring). On a system configured in this way, if you instead type vim filename, you get the full featured vim.

I just worked through this with a person who was on a server that had the vim-minimal package installed as well as another vim package. I suspect (but did not verify that) the vim-minimal package installed its executable as /bin/vi.

The difference was very clear when you looked at the actual files (i.e. ls -l /bin/vi vs ls -l /usr/bin/vim)--one was about ten times the size. Both of them were actually vim, same version number and everything, but the /bin/vi one was compiled with very few features enabled.

To make it even more confusing:

vi existing.pl

opened the .pl file, gave no syntax coloring

vi [enter]

gave the vim splash screen, and from there

:e existing.pl

opened the file with syntax coloring on.

A comment from Jan Wilamowski suggests checking by doing:

vi --version

If that shows that the syntax feature was not compiled in, try

vim --version

and see if it is compiled in there.

like image 191
msouth Avatar answered Oct 07 '22 03:10

msouth


You'll need to install the vim-data package on openSUSE for vim syntax colouring to work. Sounds strange, I know that this is not pulled in by default with the vim package but AFAIK it's for people who want to create tiny base installs. Package vim-data contains the runtime files.

Also make sure your remote environment has an appropriate TERM variable set TERM=screen-256color, TERM=xterm, TERM=xterm-256color should all work just fine with ssh and ssh with screen/tmux.

like image 43
Graham Avatar answered Oct 07 '22 02:10

Graham