Subject: Re: vi map question
To: Peter Bex <>
From: Frederick Bruckman <>
List: netbsd-users
Date: 09/24/2003 15:11:41
On Wed, 24 Sep 2003, Peter Bex wrote:

> I mapped the following combo to a key to more easily edit kernel config files:
> I, #, escape, j
> Now I can easily modify GENERIC to comment out those things I do not need (just
> hit the mapped key on a line you wish to comment out).
> (For the newbies who dig this trick: It is accomplished by typing
> :map MYKEY I#^V^[j
> Of cours)
> The question is this:
> How can I make this mapping behave as one would want it to behave 'n times' by
> typing a number before the mapped key?
> Example: assuming I bound the combo to q, typing '10q' just gives me 10 hash
> signs on the line and scrolls down to the next line. This is to be expected,
> since prefixing a number to 'i' or 'I' inserts that many instances of the
> typed string. (after which it just goes to the next line, once)

I don't see a trivial way to make this a macro, but if you make your
substition in "ex" mode, like this:


you can then repeat it 10 times at some other point in the file, like


or repeat it for a block of text (to the next non-blank line), like


The last is easy to generalize into a macro that comments out the
entire succeeding block of text (from first non-blank line to the
following blank line):

  :map <key> :/./,/^$/s/^/#/^V^V^V^M

(You have to type Ctrl-V Ctrl-V Ctrl-V Ctrl-M to get a <RETURN> into
a macro definition.)