>>    :nnoremap <f9> :.,$s/^##//<cr>
>>    :nnoremap <f8> :.,$s/^/##/<cr>
> 
> But those above look quite useful.  However I asked for a way to
> replace the `$' in your :nnoremap <f9> :.,$s/^##//<cr>
> 
> I just about never use the visual modes.. probably a bad habit.  But
> can you show me how to send vim a numeric argument ($1) along with
> :.,$1s/^##//  Where $1 contains a line number.

Ah...this description makes a little more sense.  You can omit 
the range, and if you prefix the <f8>/<f9> with a count, it will 
do that many lines.  So if you have

   :nnoremap <f8> :s/^/##<cr>
   :nnoremap <f9> :s/^##<cr>

You can then type

   5<f8>

and it will comment the current line plus the next 4 (5 total). 
It does this by acting as if you pressed the colon after the 
prefix which pre-populates the command-line with

   :.,+4

and then the rest of the mapping is executed-as-typed from there, 
making the command

   :.,+4s/^/##

and then pressing <cr> to execute the command.  This is fairly 
easy to do and works for pure counts.  For creating your own 
commenting command that makes use of "Operator-Pending" mode 
(":help operator-pending-mode"), it's a lot more complex and may 
be taken care of for you by the Commentify script Luc suggested 
earlier.  However with this, you can make it take arbitrary 
motions.  It's dark coding that I've only played with once or 
twice when I learned of the functionality.  Powerful, but complex.

> Oh and I wondered if the simple notation I used:
> 
>     nmap <F9> :.,$s/^## // 
> 
> in ~/.vimrc, is lacking in some way.  I mean you have more notation
> around it: 
> 
>     :nnoremap <f9> :.,$s/^##//<cr>
> 
> Am I likely to run into problems with the syntax I used?

There are two differences I note:

1) nmap vs. nnoremap:  I tend to use nnoremap by default because 
it prevents recursive mapping expansion.  In this case, there's 
no recursive use of "<f9>" within the expansion, so they should 
both act the same.  But by defaulting to nnoremap, I don't have 
to think about it

2) my addition of <cr> at the end.  This just means that the 
substitute command will be executed when you hit <f9> instead of 
waiting for you to hit <enter> at the prompt.

Neither of those two should cause problems.  The first one causes 
problems if you have something like

   :nmap n nzz

where the thing mapped ("n") is used in the expansion ("nzz"). 
It will recursively expand, hanging vim.  However nnoremap 
prevents this.

Then there's my obviously missing space after the "##", but 
that's my inattentiveness, not an intended difference :)

Hope this helps know more about vim, mappings, and allows you to 
modify them with greater understanding.

-tim



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to