Sunday, May 27, 2007

Enable vim syntax color highlightning in Ubuntu

Syntax color highlighting enables parts of text (tags, functions, etc) to be shown in a different color to ease the visualization of the text file, this is done based on the file extension (.php,.sql,.html,etc).

To enable this function in Ubuntu or other distros edit or create the file .vimrc which must be located in the user home directory:


vi /root/.vimrc


add this line:

:syntax enable


That's it.

20 comments:

Anonymous said...

you said:

vi /root/.vimrc


add this line:

:syntax enable

My comment is that /root is not your home directory.

Anyhow, when I tried this with my recently installed "ubuntu fiesty fawn" did:

sudo vi .vimrc
and added the line, :syntax enable

Carlos Mafla said...

The root's home directory is "/root", if you use another user you just use that particular user's home directory like "/home/user/". I use to work as root normally.

Anonymous said...

When I follow these instructions, I get:

Error detected while processing /home/xxx/.vimrc:
line 1:
E319: Sorry, the command is not available in this version: :syntax enable

(running 7.04). Any help?

Carlos Mafla said...

Try installing the vim-common package , that may solve the problem

Dave said...

Also, you do not need the ':' before syntax enable in the vimrc file. You can just place settings there. The colon is used when you are already editing a file and you must type ':' to enter the command mode.

apt-get install vim-full worked for me. Thanks for the post!

Anonymous said...

thanks that worksssss

Anonymous said...

ubuntu 7.10 comes with a small version of vim. The package is called "vim-tiny". If you want syntax highlighting just uninstall this package and install "vim" package instead which has been compiled with a standard set of features. Be aware that "vim" package does not provide a GUI version of vim. If you want that, install "vim-full" package.

Anyway, thanks to all of you guys, this post solved my syntax problem :)

Anonymous said...

You do _not_ need vim-full.

in your ~/.vimrc file enable syntax highlighting by adding 'syntax on'

Make sure you have vim-nox installed. It takes a lot less disk space than vim-full (if space is an issue). For servers, I use vim-nox.

Anonymous said...

thank you guys, this post really solved a long time headache of mine :):)

Anonymous said...

I cannot find a .vimrc file in root/ or usr/xx/ directory. There is one located under etc/vim ... But its not a hidden file.

drwxrwxrwx 2 root root 4096 2008-04-22 10:49 .
drwxrwxrwx 131 root root 12288 2008-07-13 21:27 ..
-rwxrwxrwx 1 root root 2317 2008-07-13 21:17 vimrc
-rw-r--r-- 1 root root 665 2008-01-31 04:52 vimrc.tiny

Anonymous said...

Btw, I am using ubuntu

Moot Digresson said...

I cannot find a .vimrc file in root/ or usr/xx/ directory. There is one located under etc/vim ... But its not a hidden file.

drwxrwxrwx 2 root root 4096 2008-04-22 10:49 .
drwxrwxrwx 131 root root 12288 2008-07-13 21:27 ..
-rwxrwxrwx 1 root root 2317 2008-07-13 21:17 vimrc
-rw-r--r-- 1 root root 665 2008-01-31 04:52 vimrc.tiny


I am using ubuntu

Anonymous said...

You just have to create the .vimrc file either under /root or /home/xxx/

Unknown said...

In case someone else happens to browse to this page...

I am running Ubuntu 8.10. when I added .vimrc to my home directory, it didn't change the behavior of vim.

However, I did find
/etc/vim/vimrc

and uncommented the "syntax on" line (line 20) for me.

If it is not in your vimrc, just add the line. This changes syntax highlighting for every user on the system... which may be an unintended consequence, but is exactly what I needed.

Anonymous said...

Hi it is also worked for me, I am using Ubuntu 8.10;

apt-get install vim-nox

then edit as vim /etc/vim/vimrc then enable the line from " syntax on " i.e. just remove the double inverted comma <"">

then save and exit... enjoy

روزبه دانشور said...

Thanks for reminding to change /etc/vim/vimrc
It now works for me.

raghu3532 said...

thankkkkkkkuuuuuuuuuuuu...it works even for meee...

sag said...

Hi i am using ubuntu 8.10. I didn't get syntax enable or syntax on. Then i try to install sudo apt-get install vim-full. when i gave enter is is showingAfter this operation, 0B of additional disk space will be used.
Do you want to continue [Y/n]?
then i press y
after this the following error I am getting. So please help me

Err http://in.archive.ubuntu.com intrepid-updates/main vim-tiny 1:7.1.314-3ubuntu3.1
Could not resolve 'in.archive.ubuntu.com'
Err http://security.ubuntu.com intrepid-security/main vim-tiny 1:7.1.314-3ubuntu3.1
Could not resolve 'security.ubuntu.com'
Err http://security.ubuntu.com intrepid-security/main vim-common 1:7.1.314-3ubuntu3.1
Could not resolve 'security.ubuntu.com'

sexshop espana said...

I fully agree with whatever thing you have presented.

Anonymous said...

On Ubuntu 12.04 I ran:

sudo apt-get install vim

and did not have to edit the .vimrc file at all; syntax highlighting is enabed by default.