Sep 30 2009

Vim Syntax Highlighting With .vimrc

I recently had to move all my sites over to a new host due to Lunarpages basically kicking me off. I chose DreamHost because they were having a promotion where I get a full year for $10. One of my coworkers uses them with no complaints and they give free shell access.

Vim is my editor of choice but I hate coding without syntax highlighting and DreamHost doesn’t have Vim Syntax highlighting on by default. It is possible to type “:syntax enable” when already in the editor to enable syntax highlighting on the current file that you’re editing but after closing it and opening another file you will be forced to do it again.

To enable syntax highlighting forever I had to edit the .vimrc file which lives in my home directory. It didn’t exist so I had to create one. After I created this file I added the lines :


syntax enable
set background=dark
set nocompatible
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set ruler
set virtualedit=all

Alternatively you could put ‘background=light’ which will make the colors more readable if your console is black text on a white background. The rest of those lines are just personal preference and put there so I can copy and paste them elsewhere. More info and a great example can be found at this vim site.

Share

Sep 21 2009

Vim Syntax Highlighting In Ubuntu

Spending a lot of time on the command line lately I noticed that Ubuntu does not come with Vim syntax highlighting by default. Apparently it installs a version of Vim called vim-tiny which doesn’t include any syntax highlighting.

There are two packages that you can install to get syntax highlighting to work in Vim: vim-full and vim-common. Because I didn’t have gnome installed vim-full was a very large download (like 50MB) and it errored out anyway. vim-common is definitely the way to go.


sudo apt-get install vim

The above line will replace vim-tiny with vim-common and will allow for syntax highlighting. A lot of the time you will have to enable syntax highlighting by editing the vimrc config file either in /etc/vim or in yur home directory. You will need to uncomment the line “syntax on”.

Share