Character/Word/Line Count of Selection in Vim (a non-Vimique Vim Command) Compared to Underlining Text (a Vimique Operation)

Every day I discover at least one new thing about Vim. Sometimes useful, sometimes not. Sometimes rather prosaic, sometimes sublime. This one falls in the useful but prosaic category: to get a count of the number of characters, lines, words etc. in the current selection, type “g CTRL-G”. This is a useful command, and good to know, but its invocation is a rather obscure key-mapping. In other words, just like most of the commands of your garden-variety “dumb” modeless editor, it can only be memorized (or looked up) and reproduced, instead of being generated based on grammatic-/syntactic- princples, like a language-based construct. For an example of the latter, try this ... Move the cursor to a line of text, and then, in normal mode, type “yypVr-”. This transforms:

Hello, world!


Hello, world!

A nifty little operation, and one that does not require memorization of any obscure key strokes. We are just “speaking” Vim:

  • yy“: yank (or copy) the current line
  • p“: put (or paste) the yanked/copied line
  • V“: select the (newly pasted) line
  • r-“: replace the contents with “-”, character by character

Even though more key-strokes than “g CTRL-G”, since the entire “phrase” is composed of a vocabulary of simple everyday commands/terms and can be composed from first princples, it does not need to be memorized, and hence never can be forgotten or need to be looked up. It simply is there, easily within reach of anyone who can express him- or herself in Vim.