Zhang Le's vim page
  Vim is the best plain-text editors in the world!

Though at first glance vim seems quite strange compared to other text editors: is has three different modes, hundreds of commands and very complex configure files. Configured correctly, you may be amazed at how efficient it can be when editing text files. You should read this Vim Howto if you never used vim before.

Vim VS. Emacs

I have tried to learn emacs several times before, without any success. Actually, emacs is the first Linux application that I spent weeks to learn. Even with the help of the book Sams Teach Yourself Emacs in 24 Hours, I still do not think emacs can be more productive than vim, at least for me this is true. (But I find emacs is quite popular at the Informatics division of Edinburgh. You can find someone who has been using (and addicted to) (X)Emacs for nearly two decades, well before vim was born.) The default key bindings for emacs look funny. Many simple tasks can not be accomplished without pressing two keys plus a control key like <C-X O>, <C-X b>. Quickly moving around a long document is a real pain in emacs. (However, if you can keep using (X)Emacs for years, your are guaranteed to have a pair highly trained hands for handling these key combinations with ease :-))

Emacs is a feature-rich application. I know you can read mail in emacs, but mutt+vim+procmail can easily beat emacs on this feature. Yes, I also know you can browse web in emacs, but either Lynx or Links can perform better if you only want a text-only broswer. And yes, I know the preview-latex mode is great for editing latex files. But If you have tried LyX you can see the editing experience in preview-latex+auc-latex is awkward to say at best. Yes, I know you can do edit-compile-debug circle without leaving emacs. But you can do the same task in vim as well. I confessed that emacs has much better debugger support. However, after switching to a scripting language like Python, I spent much less time on debugging C/C++ code. Simply because there are fewer and fewer tasks I think worth written in C/C++ instead of Python. I write simple Python scripts in vim, and organize complex ones in Leo.

By comparison, vim is very handy with an elegant design. Using vim, I can get full control of the editor without moving my hand away from the main (left-part of) keyboard. I do not need Control, Alt keys in most circumstances. (Instead, pressing ESC from time to time becomes my second nature :-)). The online help system is better than emacs' info interface. There are a whole host of third-party vim plugins/scripts/tips available from www.vim.org.

I must admit, however, there are still tasks where emacs performs better than vim. This gives me a reason to remain a copy of XEmacs installed on my machine. For example, XEmacs does a decent job on maintaining BibTeX files. I appreciate emacs's ability to intelligently sort and validate entries in a BibTeX file.

My conclusion is that for plain text editing, the very purpose of a text editor, vim is obviously a better choice than emacs. And for complex tasks, there are always better tools specially tailored for the tasks.

Extending Vim

Much of vim's power come from its plugin system. A vim plugin is a set of vim scripts that perform certain operations from removing blank lines in a buffer to a full feature shell window.

The following plugins are recommended here for I find them really useful. You can get all of them in my vim config file.
vimspellispell or aspell based spell checker with fly-spelling
bufexplorEasily switch between buffers without knowing their numbers
autodateA customizable plugin to update time stamps automatically.
taglistSource code browser (supports C/C++, java, perl, python, tcl, sql, php, etc)
aAlternate Files quickly (.c --> .h etc)
AlignProvides commands and maps to help produce aligned text, eqns, declarations, etc
SuperTabDo all your insert-mode completion with Tab key!

My Vim Configurations

Here are some handy key bindings defined in my vim config file. (the starting " are comments). Just extract the tar ball to your home directory (or c:\vim63\ if using windows). It should work out-of-box on both unix and win32 system with vim6.2+ installed.

" normal mode:
" Q      quit vim without saving
" W      quit vim after saving all buffers
" C      call Compile() to compile current file
" H      scroll screen up like pageup
" L      scroll screen down like pagedown
" S      call aspell to do spell correction
" ,,     jump to tag under cursor, same as <C-]>
" ..     jump back to last position, same as <C-T>
" ,b     open buffer explorer
" ,h     update tag list window
" ,t     open tag list window
" ,w     open winmanager file explorer window
" _Y     yank text to a temp file
" _P     paste text from a temp file
" ,u     reload vimrc file
" ,v     view vimrc file
" ;b     reduce a sequence of empty lines into a single line
" ;n     reduce a sequence of blank lines into a single line
" \z     fold matched lines after a search
" gf     open filename under cursor
"
" <F3>   quickfix next error
" <F4>   quickfix previous error
" <F8>   equal split windows
" <F9>   Grep word under cursor
"
" <C-S>  save current buffer
" <C-j>, <C-k>, <C-h>, <C-l>  quickly move between split windows
" 
" insert mode:
" <C-j>  ??? 
" <C-A>  <Home>
" <C-B>  <Left>
" <C-E>  <End>
" <C-F>  <Right>
" <C-D>  <Delete>
"
" visiual mode:
" <C-m>  call EnhancedCommentify to comment/uncomment current selection
" _Y     yank text to a temp file
"
" Abbreviations:
" Ydate  insert current date eg:2005-01-06 
" Ytime  insert current time eg:20:16 
" Ydt    insert both date and time eg:2005-01-06 20:17 

Links


Last Change :27-Jun-2005. Please send any question to Zhang Le