Book Review: Practical Vim: Edit Text at the Speed of Thought by Drew Neil

Camilo Matajira Avatar

In Practical Vim, Drew Neil gives us an all-around perspective of how to work with Vim.
The author divides this book into 123 tips, each exposing an interesting Vim functionality.

The book is great (not only for covering very interesting Vim tips), it is great because you can take a grasp of how an experienced Vim user thinks about problems. We get a flavor of the author’s style.

Who is this for

Despite the book is beginner-friendly, I think people who already know the basics off Vim can profit more from reading the book. By the basics, I mean being able to do daily activities using Vim.

Besides, I think that to be able to profit from this book you need some kind of system that allows you either to memorize the good material or to store it and retrieve it fast. Otherwise, you will soon forget what you learn. In my case I use Anki. I read the book with Anki by my side, when I saw something interesting I convert it into a flashcard. I try to review the flashcards every day. This way, Anki helps me memorize the key insights and tips I get from the book. You should have a similar system in place.

My main take-aways:

I believe the most interesting takeaways of the book will vary from person to person depending on your previous knowledge of Vim. For me, these are my key take-aways:

Dot command

The dot command is Drew Neil’s favorite command. It is the cornerstone of Drew Neil’s approach to Vim. I did not know how useful this command was until I read this book.

The basic idea of the Dot command is that with it you can make Vim repeat the previous change. A change is not only deleting a letter or inserting a character, is everything that happens between you entering into insert mode and when you return to normal mode. Hence you can use the dot command to repeat several modifications with a single keystroke.

The most powerful use of the Dot command is to think the problem through until you can devise a strategy in which you move with a single keystroke, and modify with a single keystroke (the dot command). To cite Drew, “this is as sweet as it can get”.

Star (*) command

I haven’t heard of the star command until I read the book. I think it is very useful especially mixing it with the dot command.

When you are in normal mode if you type * it will look across the document to all the mentions of the word the cursor is currently on. If you type ‘n’ you can start switching between matches of the word.
You can also modify the word, and continue cycling with ‘n’. Hence this allows you to cycle between searching for a word, modifying it in some way (for example using the dot command), and continue to the next word, etc.

As mentioned while discussing the dot command, the idea is to be able to move with one keystroke (in this case ‘n’) and perform a modification with a single keystroke (for example with the dot command).

This is interesting because, despite you can use the substitute command to search and replace, you can do the same in a faster way with the * command.

Normal command

The normal command allows you to repeat ‘normal mode’ commands in the Vim Ex command prompt. The idea is basically that you can select, for example, a range of lines, go into Ex mode (by pressing 🙂 and then apply a normal mode command to all the selected lines.

Examples of normal mode commands are the dot command, d to delete, A to append text at the end, I to insert text at the beginning, etc. Don’t forget that you can also do more complex ‘normal mode’ commands, for instance: Acamilo will append the word ‘camilo’ at the end of the line.

Global command:

The global command is very powerful because you start with a range of lines, then you can filter those on which you want to do some modification, and finally, you execute a ‘normal mode’ command.

According to Drew, the famous grep command comes etymologically from the global command. :g/re/p –> g: global, re: regular expression, p:print.

Very magic pattern

I appreciate from Practical Vim that it took several tips discussing regular expressions in Vim, especially the very magic pattern. The very magic pattern is an option that allows vim regex to resemble more the regex done in Perl, Python, and Ruby. In this sense, you don’t need to scape (){} and other symbols that have special meaning in the regular expression, you can simply use them and this greatly simplifies typing the regex.

Filtering the contents of a buffer through an external command

I found this one sweet. Basically, it allows you to combine Vim with any other shell command. This is particularly useful for people who know command-line tools like awk, sed, cut, tr, grep, sort, uniq, etc.
You can select some lines of text in Vim, send them to the shell as standard input, and get the result back replacing the original lines. In other words, you can apply your favorite command-line tools to any text inside Vim. I find that very useful.

Conclusion

Finally, I would recommend this book to all Vim users. Given that Vim is big, we should all strive to become proficient as fast as possible. This book helps in this endeavor because it summarizes several of Vim’s interesting functionality in a single book that you could read in a couple of days.

Tagged in :

Camilo Matajira Avatar