Blogged by Ujihisa. Standard methods of programming and thoughts including Clojure, Vim, LLVM, Haskell, Ruby and Mathematics written by a Japanese programmer. github/ujihisa

Friday, November 5, 2010

The Problem and Solution of Haml

When I write an HTML file I always write in Haml first and generate HTML by haml command. Haml is so handy that Haml makes us free from writing closing tags like </p>. The problem in Haml is that it is very difficult to type % very often. The symbol is the second most difficult location (*1) in a keyboard.

The solution is to write the following code on you ~/.vim/ftplugin/haml.vim which let : key as % only in Haml file and when the cursor is on the top of the line.

inoremap <buffer><expr> : <SID>on_the_top() ? '%' : ':'
function! s:on_the_top()
  return col('.') == 1 || getline(line('.'))[0:col('.')] =~ '^\s*$'

Note that I swapped : and ;. If you didn't swap them, just to swap your keyboard or the code.

  • (*1) The most difficult location key is ^ (shift + 6). If you want to make a programming language which is highly difficult to code, use ^ a lot.

No comments:

Post a Comment