Thursday, April 9, 2009

Colorizing Code in vim

This is an esoteric topic, but if you know what vim is, this entry may help you get your code colorizations set up to your liking.

There are two topics to be discussed here.  (1) setting up your code colorizations, and (2) making vim recognize the code type that you are editing.

1.  Setting up .gvimrc (or .vimrc) to colorize your code with your color choices:

     - Within this topic, there are two alternatives:  
        (a)  you are using X, so you have fine-grained control over the color set.
        (b)  you are using some kind of color tty terminal (puTTY for example), in which case you can only use the basic 8 or 16 colors.

     - In the example that follows, these contents are typically found in the .gvimrc file which should be placed in the user's home directory.  (_gvimrc for Windows).  For tty terminals, you will need to define a .vimrc softlink to the .gvimrc file.



" Only do this for Vim version 5.0 and later.
if version >= 500

  " Turn off Tool Bar:
  set go=agimrt

  " Highlighting strings inside C comments
  let c_comment_strings=1
  let c_comment_strings=0

  " Switch on syntax highlighting.
  syntax on

  " Switch on search pattern highlighting.
  set hlsearch

  " For Win32 version, have "K" lookup the keyword in a help file
  "if has("win32")
  "  let winhelpfile='windows.hlp'
  "  map K :execute "!start winhlp32 -k " . winhelpfile
  "endif

  " Hide the mouse pointer while typing
  set nomousehide

  " Set nice colors:

  " There are two sets of defaults: a dark and a light background.
  " You can set up as many different versions as you like.

  set background=light
  set background=dark

  set guifont=fixed
  "set guifont=helvR14
  "set guifont=ncenR14
  set guifont=hp8.8x16
  "set guifont=hp8.10x20b

  if has("gui_win32")
      :set guifont=Lucida_Console:h8:cANSI
  endif

  if &background == "dark"
      hi Normal     ctermfg=White         guifg=#a0ffff    guibg=#402850
      hi Comment    ctermfg=Yellow        guifg=#ffff80    guibg=#402850
      hi Constant   ctermfg=Green         guifg=Green      guibg=#402850
      hi Special    ctermfg=Magenta       guifg=#80ffd0    guibg=#4028c8
      hi Identifier ctermfg=Cyan          guifg=#00c0ff    guibg=#402850
      hi Statement  ctermfg=White         guifg=white      guibg=#402850 gui=bold
      hi PreProc    ctermfg=Magenta       guifg=#ff00ff    guibg=#402850
      hi Type       ctermfg=Blue          guifg=#0000ff    guibg=#402850 gui=bold
      hi Ignore     ctermfg=Grey          guifg=Grey       guibg=#402850

      hi Error      ctermfg=Red           guifg=White      guibg=Red
      hi Todo       ctermfg=Magenta       guifg=#ffffa0    guibg=#402850 gui=bold

      hi Search                           guibg=#d0d000
      hi Visual     ctermfg=Blue          guifg=DarkBlue   guibg=Cyan
      hi Cursor     ctermfg=NONE          guifg=NONE       guibg=Green
      hi NonText                                           guibg=#a0a0a0
  else
      hi Normal     ctermfg=Black         guifg=Black
      hi Comment    ctermfg=DarkYellow    guifg=Brown
      hi Constant   ctermfg=DarkGreen     guifg=DarkGreen
      hi Special    ctermfg=DarkMagenta   guifg=DarkCyan   guibg=#e0ffe0
      hi Identifier ctermfg=DarkCyan      guifg=DarkBlue
      hi Statement  ctermfg=Black         guifg=Blue                     gui=bold
      hi PreProc    ctermfg=DarkMagenta   guifg=Purple
      hi Type       ctermfg=Blue          guifg=Black                    gui=bold
      hi Ignore     ctermfg=DarkGrey      guifg=White

      hi Error      ctermfg=Red           guifg=White      guibg=Red
      hi Todo       ctermfg=Magenta       guifg=Blue       guibg=Yellow  gui=bold

      hi Visual     ctermfg=DarkBlue      guifg=DarkBlue   guibg=Cyan
      hi Cursor     ctermfg=None          guifg=NONE       guibg=Green
      hi NonText                                           guibg=#808080
  endif
endif



2. Getting vim to recognize the file type for correct code colorization:

    - In following example the code colorization parser is set based on the file extension and only works in gvim.


" gretl provides a nice, simple colorizing to differentiate typical
" delimiters, text and numbers:  Other reasonable choices: fstab, rexx
augroup filetypedetect
  autocmd BufNewFile,BufRead *.cfg   setfiletype gretl
  autocmd BufNewFile,BufRead *.dbg   setfiletype gretl
  autocmd BufNewFile,BufRead *.log   setfiletype gretl
  autocmd BufNewFile,BufRead *.lst   setfiletype gretl
  autocmd BufNewFile,BufRead *.out   setfiletype gretl
augroup END

Saturday, April 4, 2009

SATA II Hard Drive Blues...

I have killed so many computers messing with the hard drive configurations over my lifetime that it should be illegal for me to even touch my computer with a screwdriver.  But, like Mr. Anderson of the Matrix, I persist because "I choose to"...

So I have an HP Pavilion DV9000 laptop with two Toshiba MK1237GSX 120 GB SATA hard drives factory installed. I wanted to upgrade the secondary drive to a Samsung HM500LI 500 GB hard drive. I installed the drive and the system eventually came up after 5 mins of some kind of internal existential struggle... ;^) Unfortunately in that struggle, the hard drive lost, and was nowhere to be found, not even after asking the computer to scan for new devices...

After a few internet searches I learned that my new drive was SATA II and was somehow not being recognized by the system at all. Perhaps because my computer's primary drive was SATA I?  Anyway, Samsung's website references the possibility of jumpering the drive to halve the throughput from 3 GB/sec to 1.5 GB/sec, but does not actually show how the jumpers are supposed to be placed. (What the heck is wrong with these people??)  Ultimately my solution was to jumper the device by trial and error, with this drive the jumper was correctly placed when it was connecting the outer-edge-most two of the 4 jumper pins. Once the jumper was installed, the disk came up and was immediately recognized by the system.

Actually I can't really see any performance difference between this drive and the other drive running at native speed.  Perhaps the fact that the drive is only spinning at 5400 rpm is the more limiting factor.