New Vim Tips

Here are some more Vim tips I collected recently:

  1. One can repeat the last t, f, T or F command which moves to the next specified character in a line, or right before that, using ;, and repeat in the opposite direction using ,. I discovered those after starting to read through the vim usr_* manuals.
  2. One can get the Unicode value of the character under the cursor using the :ascii command-line command or the ga normal mode command.
  3. If you want to find how many lines/words/etc. are in a visual block, you can select it using “v” and friends and then type g-Ctrl+G.
  4. Finally, you can pipe the contents of the buffer or a range to an external program and view its output temporarily. So you can say :w !grep 'FOO' | wc -l to find the number of lines containing ‘FOO’, or :'a,'bw !grep 'FOO' | wc -l within a range.

I should note that one thing that annoyed me lately, is the fact that after I have a visual selection (v or V), I sometimes press u instead ofy (because they are so nearby) and so cause the selection to become lowercase instead of yanking it.

Happy Vimming!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: