Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Friday, October 8, 2010

viper-mode in emacs

I love vi for its simplicity. Vi is a very powerful tool. I use vim (Improved vi) to edit program files. It saves a lot of my time. But, vim has a drawback. Vim does not support Japanese input very well. In vim one have to use ESC key frequently. When you use scim-anthy to input Japanese, after pressing ESC you cannot use the movement commands because of the Japanese character inputs. You have to stop Japanese IME and then move around the file.

For the above reason, I use Emacs to edit Japanese files mainly latex files. In my lab, I need to make materials for meetings in Japanese. In Emacs you can use plug-ins for latex file editing. It makes editing latex files very easy. I am quite happy with my latex plug-in (Yatex) in Emacs.

But, Emacs functions to move around a file is little bit complex. Vim style of movement suites me more that Emacs style. That is why I was desperately looking for a solution to edit Japanese files in Vim seamlessly (Without turning on/off the IME). While searching I found the following thing.

Emacs has a plug-in named "viper-mode" which emulates vi in Emacs. The first time I saw this, I knew that this is the solution what I wanted. Using this plug-in, now I can use all the Emacs functions and at the same time I can move around the file and edit file in vi style. Its just like a dream.

I have just started using this. I need to learn few things to customize it to my likings. But for now, I am happy to find this.

Wednesday, July 28, 2010

Embedding formatted code into webpage

I wanted to write a post on ruby option parser. I wanted to add some code to the post but then I realized that Google Blogger does not provide any tool for formatting code and syntax highlighting. It would be so nice to have a tool for embedding program codes into the blog. At first, I became frustrated with Blogger, then began to search for some solutions.

After some searching, I found the solution which I liked very much. Its vim's "TOhtml" feature. I liked this feature because I use vim for code writing. So, I do not have to go to any other tool. Next, it converts the code into html format which I can embed in any webpage which is great.

But, the default html from vim's TOhtml did not look very clean. It seems that the color I see in my terminal and the color I see in browser are quite different. I found this article which gives an guideline on how can we change the html output by doing some simple vim scripting. I almost followed his way completely, except that he used a different color scheme plugin for vim where I decided to change the style sheet for changing the look. Here's one example of ruby code outputed using the vim's TOhtml feature.

$VERBOSE = nil
require 'gnuplot'

outfile = "test.obj"
plot = Plot.new
x = (0..50).to_a
y = x.collect { |v| v**2 }
data = DataSet.new([x,y])
plot.data << data
plot.term "tgif"
plot.output outfile
plot.plot

Isn't it clean enough? I like it. It's easy to do. Run command in vim, copy the code and then paste in the Blogger. I am hoping to post articles on programming languages from now on and this method will give me a good boost.