APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Vim: edit with vim

2009/10/04 by Girish Venkatachalam

Girish Venkatachalam is a UNIX hacker with more than a decade of networking and crypto programming experience. His hobbies include yoga,cycling, cooking and he runs his own business. Details here:

http://gayatri-hitech.com

http://spam-cheetah.com

I type

$ dict vim
 vim
       n 1: a healthy capacity for vigorous activity; "jogging works off
            my excess energy"; "he seemed full of vim and vigor"
            [syn: {energy}, {vitality}]
       2: an imaginative lively style (especially style of writing);
          "his writing conveys great energy" [syn: {energy}, {vigor},
           {vigour}]

and got this along with the idea that there is also an editor by name Vim of course. It also goes on to tell me that Vim stands for "VI Improved".

For people who hate vi, vim does not offer much relief. They might end up hating vim as well and sing paeans for emacs.

Long ago I wrote an article claiming that I write my e-mails in Vim and that led to a very interesting and sometimes annoying flame war in that site. There seems to be a lot of passion that goes behind arguments for deciding which editor is better: vi or emacs.

I stopped using emacs a decade ago. I did use it though. When I was in college. My fingers started aching though I use the keyboard a lot more now than those days.

The C-X C-C combinations and other combinations in emacs left my fingers lusting for relief. But I used to think in those days that emacs must have something in it to attract such fanfare.

I do not recollect at what point I discontinued emacs but I know for sure that I never used emacs in the last 10 years or so. Interestingly not a single coding day would pass without my opening vi or vim.

It was later that I realized that an editor is not used for coding alone. An editor after all is necessary for every form of computer input involving characters!

My product SpamCheetah has a keyboard shortcuts facility which makes you even navigate the feature rich web interface using keystrokes. Real geeks do not use the mouse; they prefer the speed and convenience of keyboards.

And real geeks need real editors. They won't sing paeans about a WYSIWIG editor. They want a power editor. An editor that can serve as a friend, philosopher and guide. They want an editor that can make them really efficient, an editor that can automate mundane tasks. They want an editor...sigh!

It is too hard to meet the demands of geeks. So I better stop.

In case you are wondering,I type this article in Vim. I create PDF files in Vim using LaTeX, I code using vim, I write e-mails in Vim...I do everything with vim using Vim.

Vim protects my fingers against wear and tear, vim highlights the syntax for my C coding projects, config file editing moments and helps me immensely when I learning new programming languages.

The same editor also helps me identify spelling errors when I set

:se spell spelllang=en_US
 

and very interestingly it was vim that helped me create this most amazing page.

Chanakya quotes using fortune

I created a fortune file of Chanakya quotes from a web page by copy pasting them into a vim buffer. I searched for digits and "." and removed them like this.


:%s/[0-9]*//

:%s/\.//
 

Then I inserted the '%' character by this command:

:%s/^$/%/g
 

The above line searches for blank lines identified by a beginning of the line anchor '^' and end of the line anchor '$'.

I then went on to create a fortune db using this command:

$ strfile chanakya chanakya.dat
 

Then copying these two files into /usr/share/games/fortunes on my Debian box was all that was necessary for this:

$ fortune chanakya

I was happy with the result. But I had to fix certain inconsistencies and fix problems. One nice thing I did was this:

:%!fmt -w 60
 

This command formats the entire document to break at 60 columns without breaking words of course.

Then I wrote this CGI script:


#!/usr/local/bin/perl -w
use CGI;

 $q = new CGI;
 print $q->header,
 $q->start_html('Chanakya quotes [Press F5 for a new quote]');

 $out = `/usr/games/fortune /spam-cheetah.com/cgi-bin/chanakya`;

 $q->h1('Chanakya quotes [F5 for a new quote]');
 $q->print('<br></br>');
 $q->print('<br></br>');
 $q->print('<br></br>');
 $q->print('<br></br>');
 $q->print('<br></br>');
 $q->print('<br></br>');
 $q->print('<br></br>');
 $q->print('<br></br>');
 $q->print('<br></br>');
 $q->print("<em>");
 $q->print('<pre>');
 $q->print($out);
 $q->print('</pre>');
 $q->print("</em>");
 $q->end_html;


Such is the power of this fantastic editor. If you keep using it, your efficiency increases by leaps and bounds. And after a long time you become so acclimatized to the vim way of doing things that it comes naturally to you.

Vim also has an excellent help system. You can invoke help on any topic with the ":help" command. It can also be navigated using the 'C-]' keystroke used with ctags. I cannot dwell too much upon it. Please see this article for some details.

In case you like the quotes you can download the fortune files from here:

  1. chanakya
  2. chanakya.dat

In case you are wondering who Chanakya is, he is one of the foremost intellectuals who lived during the 350 BC time frame. Refer wikipedia for more details.

He is the master of traditional Hindu wisdom and a manipulator and diplomat beyond compare!



Got something to add? Send me email.



5 comments



Increase ad revenue 50-250% with Ezoic


More Articles by © Girish Venkatachalam







Sun Oct 4 12:27:50 2009: 7060   TonyLawrence

gravatar
Every post I write here is done with vi, as are all my scripts and anything else.

Back when I started, emacs needed too much ram for what you'd typically find on small machines, so it wasn't always avaiable. Vi was always there, so it was an easy decision to learn vi rather than emacs.



Sun Oct 4 16:08:00 2009: 7064   BigDumbDInosaur

gravatar
Same here with EMACS. The boxes that I had available to me 20-25 years ago were too weak in the knees to support a resource hog like EMACS. It would run but it seemed as though it took forever to get anything accomplished. So despite the fact that the current hardware will readily run EMACS with alacrity, I still type vi when i need to edit something. Old habits die hard, I guess.



Mon Oct 5 12:30:45 2009: 7070   MikeHostetler

gravatar
Finally get a chance to voice my $0.02.

It's very funny, but my experience is the opposite of Girish's -- I started with vi/vim and moved to Emacs. The reasons are varied, but it coincided with my career shift from a sysadmin to a developer. As a sysadmin, I had to edit a file and get out. With that, vim is good. But if I'm sitting in the same file all day long, or move back and forth between several files, I found Emacs a much better fit.

Another great thing about Emacs is that, since it has been around long enough, all the problems have been solved. Whenever I think "I wish X worked a bit differently. . . " and then I head over to (link) and find someone else's solution for it.

I'm not saying that Vim is bad -- I think it's a good tool for the right job. I just think that Emacs is a better tool for other jobs.

Eric Raymond has great thoughts on Unix and Editors in his Art of Unix Programming. That is what finally convinced me to turn to the Emacs Way.

(link)



Mon Oct 5 12:45:30 2009: 7071   TonyLawrence

gravatar
Ayup - that's why I put your "Why I am changing to emacs" article in the "Related Posts " part in the sidebar.



Mon Oct 5 13:05:27 2009: 7072   Peter

gravatar
Mike's post can be misread as vim not being the right job for coding. Which is wrong:

Vim's approach for complex editing doesn't use emacs' insert-mode-only Meta-x plus LONG-COMMAND-NAME (emacs doesn't implement modal input in the sense of vi/vim), but you _should_ rather try to always stay in normal mode and use mappings and sometimes command-mode to enter a rarely used :COMMAND or :call FUNCTION.

Check out the vim screencast series on youtube. An eye-opener.

Vim's problem is that it's far too convenient to just stay at the level Mike describes, doubly so with the improvements(?) of insert mode over the original vi. Read-single-file-small-edit-write-leave.

Maybe if vim would be a bit harder to use (esp. in insert-mode!), people would have more incentive to go beyond that level. The original vi was painful enough to force more people to learn about mapping and thus leave that dreaded 'insert-mode-single-buffer-plateau' of vim-skill-failure.

cu
Peter

------------------------
Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





Writing in C or C++ is like running a chain saw with all the safety guards removed. (Bob Gray)

Technology is anything that wasn’t around when you were born. (Alan Kay)










This post tagged: