Review of Hacking Vim 7.2

vim_logoHacking Vim 7.2 by Kim Schulz is filled with a variety of useful explanations and helpful tips for Vim users wanting to improve their efficiency and learn more about their editor. While I’ve enjoyed finding new and better ways to use Vim for some time, I still learned quite a lot from this book.

If you use Vim only to edit text files when you happen to be logged into a CLI: mosey on along, this isn’t the book for you. If you currently use Vim regularly and want to improve your knowledge and effectiveness with it: your time reading this book will be well-spent. If you’ve somehow never heard of Vim but are enraptured by the idea of a text editor that can be an effective IDE in addition to allowing you to play Tetris and Rubik’s Cube: you might like this book too.

At first this book seemed rather short for such a potentially expansive topic. In the end I found this to be mostly a virtue rather than a problem, as the amount of information presented is, in fact, voluminous. A more comprehensive approach likely would have been too hefty and less effective. It doesn’t pretend to be a manual for Vim. Instead it illustrates the best approaches for various issues and situations, suggests improvements on more common operations, and provides lots of references to external resources (primarily Vim internal help and vim.org) to learn more. Examples and illustrations provide insight into some of Vim’s lesser known abilities, while commonly used ones are explained and presented in new and useful ways. Groups of features resolve into solutions.

Chapter by Chapter

Chapter 1, Getting Started with Vim

Primarily a history of the Vim editor. Useful to expand the knowledge of Vim fans, but not really pertinent to hacking your beloved editor. Would probably have been better as an appendix or excised entirely.

Chapter 2, Personalizing Vim

Editing your Vim config, customizing fonts, colors, menu buttons and other UI elements. Lots of great material for tuning the visual appearance. More about vim.org and other resources for colorschemes (such as this gem) would have been helpful. The ability to add tooltip balloons was new to me and quite exciting. Schulz provides a number of great examples for their use. The discussion of abbreviations was a bit confusing, especially considering the recommendation of the more intuitive snippets approach in Chapter 4.

Chapter 3, Better Navigation

By now you might already be feeling overwhelmed by the number of key commands to remember. I recommend starting a cheat sheet of those you find especially interesting. Speaking of that, perhaps it’s just my predilections and lack of a perfect memory, but the vast number of code navigation keys was just a bit too much. Sure, “extra keys pressed equals extra time wasted”, but what about extra time sorting through key commands in your thoughts? Still, plenty of tips should be mind-blowing if new to you. Jumping to files named in the text of the current file, for example, is really handy. The information about search improvements, both in user files and in the help system, was quite good. I’ve yet to really use signs or marks, but found their explanation here illuminating.

Chapter 4, Production (Productivity?) Boosters

Templates! Templates are awesome, and this was a welcome introduction to a topic I’ve barely scratched in my Vim journey. I’ve also not used placeholders in templates before, which look to be quite useful. Tag lists and essential plugins for their use are explained, providing an effective presentation of this feature. I was getting a little worried around pg. 86, as the number of Ctrl + x, Ctrl + SOME_KEY commands started to get cumbersome. Then came the explanation of triggering all completion types using a single key, which was quite refreshing. Complete using dictionaries, words in the current document, language files, and more, all using a single key. The SuperCleverTab function will be a very welcome addition to my configuration. Until seeing the example about macros, I never really felt how useful they might be. This definitely convinced me.

But this meaty chapter isn’t over yet! Sessions felt rather opaque to me before reading this section, and I think they will now definitely serve a role for me. No more ritual of opening the right files, folding them just how I want, etc every morning. Undo branching… I still find this rather too complicated and marginal of a feature to care about. But the examples were at least explanatory. Folding is a great eye-saver, and the coverage was adequate. I’m still not really a fan of vimdiff, as there are other diff utilities out there that make the process faster and more intuitive to me. One exception is finding the diff between the current buffer and the saved file, which is very handy and not something available in most editors for sure! I hadn’t opened remote files in Vim directly before, so the section on this at the end of this chapter was quite useful.

Chapter 5, Advanced Formatting

I felt mostly ambivalent about the beginning of this chapter. To me, if you want text aligned a certain way, or want to create proper lists and use other more advanced document formatting features, you should use a word processor. Adding whitespace to my text files for alignment’s sake doesn’t strike me as a good idea.

The second part covering formatting pertinent to coding was much more useful. I’ve used things like autoindent and formatting of pasted code for a while now, and they are quite essential to sanity. Great coverage for those new to these features. Integration of external formatting tools such as Tidy is also described.

Chapter 6, Basic Vim Scripting

Now we get to it” was my feeling starting this chapter. There’s some very helpful stuff in here, but it’s strangely organized and should have been moved or at least mentioned earlier in the book to provide the most benefit. Some critically handy items: explanation of Vim configuration file directories, how to properly override layers of configuration, Vimball installation, syntax highlighting and colorscheme creation. Then… comes an introductory language tutorial. Honestly, it’s pretty dull and mostly elementary. I would have rather this been moved to an appendix mentioned early in the book. It does provide broad coverage of the basics one would need to start writing Vim scripts.

Chapter 7, Extended Vim Scripting

Everything you need to know about actually writing Vim scripts: suggested code format, function structure, adding key mappings, detecting OS and Vim version, debugging and distributing scripts, documentation, even integrating programming languages like Python and Ruby! This is certainly a great reference to get started with Vim scripting. Schulz also gives an example script wrapping up a number of these points, providing something like a Vim scripter’s “Hello World”.

Appendix A, Vim Can Do Everything

Examples of the many and varied things you can do with Vim, such as Tweet and play Tetris. Provides amusement, but not a lot of value. The section on Vim as an IDE should really have been expanded to an entire chapter or appendix considering the likely audience for this book.

Appendix B, Vim Configuration Alternatives

A number of tips on how to keep your Vim configuration organized. Spends time explaining a system of scripts created by Jos van RisWick that allows the user to make changes to their configuration from GUI menus and make them permanent, instead of editing config files. I had never heard of this and found it quite interesting.

The last few pages deal with storing your Vim configuration online. While I whole-heartedly agree with the intent, the particular manifestation presented is rather terrible. Using this setup, the user’s .vimrc would be downloaded every time Vim is opened. Then it still has to be parsed, which for heavily customized setups can already take a moment. Not the best when you’re looking for a lean editor. And what about the legion of scripts and other supporting files outside .vimrc? I think not. My approach to the problem is to keep all of my Vim configuration files inside an SCM system, checking it out on each system the first time I want to use Vim.

Issues

  • Confused structure: Chapters 6 and 7 felt rather strangely divided in themselves, and I felt most of the content should have been provided earlier. Having a better knowledge of the syntax and nature of ex commands/Vim scripting would have made the content throughout the book more understandable. I felt I was mostly taking the syntax in the code provided for granted, without feeling comfortable enough about all the components that I could have written something of my own design.
  • Typos: The text would have greatly benefited from another round of copy-editing. Most of the errors weren’t very distracting. There were, however, a number of typos in the code provided that were more problematic, especially for a work on an editor that can be rather picky about commands. For a first edition, these aren’t overly numerous.
  • Lack of color diagrams: I’m all for using black and white images when they will suffice, but when providing illustrations of *color* highlighting files, images without color are downright useless! I was rather surprised at this oversight, first appearing in chapter 2, then in multiple places in chapter 6. They could have at least linked to color images online.

Conclusion

All in all this was a very useful treasure trove of tips. Some I’ve already added to my repertoire, and more I’m trying to understand better. In fact, I learned so much from it that I decided I will likely need to drop most of my current Vim config and remake it cleanly. I know I’m not alone in collecting bits and pieces of configuration for this wonderful editor, in a fashion occasionally reminiscent of a deranged hermit crab. Now that I have a more solid understanding I can rebuild it quickly and effectively.

In summary, I agree with Brian Carper:

The best you can hope for in a book is a broad outline to point the way toward features that you didn’t know much about. Hacking Vim 7.2 achieves this goal.

Be Sociable, Share!

Post to Twitter Post to Delicious Post to Digg Post to Reddit

This entry was posted in Book Review, Programming, Python, Ruby, vim and tagged , . Bookmark the permalink.

3 Responses to Review of Hacking Vim 7.2

  1. The one area I wish would be covered in any book or documentation is ftp login for remote files. However, I agree with you this is a great book.

  2. @octopusgrabbus Actually that is covered (along with SSH and others) on pg 115-119 in Hacking Vim 7.2. It’s a really simple format: http://vim.wikia.com/wiki/VimTip337

  3. John Wiersba says:

    BTW, this is not a first edition. It is almost identical to the 2007 version: Hacking Vim.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>