Quantcast

Use count as argument for a map

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Use count as argument for a map

esquifit-2
I have a bunch of numbers and for each of them I have to find all
occurrences in a file, that is: for the first number, find all lines
containing the number, for the second one the same, and so on.  Since
this is repetitive process, I'd like to minimize the number of key I
have to type. I'm trying to get something like this to work:

345<F7> -->  display all lines containing '345'

For a fixed number, this would be something like

nnoremap <F7> /\<345\><CR>[I

However I cannot see how could I pass the numeric argument to the
mapping.  I've tried mapping keys to commands where I'm allowed to use
things like <count> or <args> and even functions, but I'm still
failing to find a solution.    I'm aware that I'm trying to (ab)use a
*count* as an *argument* and that this is probably why there is no way
to achieve what I'm attempting, but you never know, therefore I'm
asking here.

For this specific task there are possibly alternative solutions, like
making a new buffer with all numbers that need to be looked up and
then running a script that would do the job. Anyway, I'd like to know
if the above is possible at all and how.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Use count as argument for a map

Gary Johnson-4
On 2012-04-24, esquifit wrote:

> I have a bunch of numbers and for each of them I have to find all
> occurrences in a file, that is: for the first number, find all lines
> containing the number, for the second one the same, and so on.  Since
> this is repetitive process, I'd like to minimize the number of key I
> have to type. I'm trying to get something like this to work:
>
> 345<F7> -->  display all lines containing '345'
>
> For a fixed number, this would be something like
>
> nnoremap <F7> /\<345\><CR>[I
>
> However I cannot see how could I pass the numeric argument to the
> mapping.  I've tried mapping keys to commands where I'm allowed to use
> things like <count> or <args> and even functions, but I'm still
> failing to find a solution.    I'm aware that I'm trying to (ab)use a
> *count* as an *argument* and that this is probably why there is no way
> to achieve what I'm attempting, but you never know, therefore I'm
> asking here.

    :help v:count
    :help v:count1

HTH,
Gary

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Use count as argument for a map

Ben Fritz
In reply to this post by esquifit-2
On Tuesday, April 24, 2012 2:05:59 AM UTC-5, esquifit wrote:

> I have a bunch of numbers and for each of them I have to find all
> occurrences in a file, that is: for the first number, find all lines
> containing the number, for the second one the same, and so on.  Since
> this is repetitive process, I'd like to minimize the number of key I
> have to type. I'm trying to get something like this to work:
>
> 345<F7> -->  display all lines containing '345'
>
> For a fixed number, this would be something like
>
> nnoremap <F7> /\<345\><CR>[I
>
> However I cannot see how could I pass the numeric argument to the
> mapping.  I've tried mapping keys to commands where I'm allowed to use
> things like <count> or <args> and even functions, but I'm still
> failing to find a solution.    I'm aware that I'm trying to (ab)use a
> *count* as an *argument* and that this is probably why there is no way
> to achieve what I'm attempting, but you never know, therefore I'm
> asking here.
>
> For this specific task there are possibly alternative solutions, like
> making a new buffer with all numbers that need to be looked up and
> then running a script that would do the job. Anyway, I'd like to know
> if the above is possible at all and how.

I might try using the search() function and the v:count variable rather than a / search. <count> is for user-defined commands using the :command command, not for mappings using the :map command set.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Use count as argument for a map

esquifit-2
In reply to this post by Gary Johnson-4

On 24 Abr, 16:50, Gary Johnson <[hidden email]> wrote:
> On 2012-04-24, esquifit wrote:
>
>     :help v:count
>     :help v:count1

This does the trick indeed. Thank you!
e.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Use count as argument for a map

esquifit-2
In reply to this post by Ben Fritz

On 24 Abr, 16:51, Ben Fritz <[hidden email]> wrote:
> On Tuesday, April 24, 2012 2:05:59 AM UTC-5, esquifit wrote:
> > I have a bunch of numbers and for each of them I have to find all
> > occurrences in a file, that is: for the first number, find all lines
> > containing the number, for the second one the same, and so on.

> I might try using the search() function and the v:count variable rather than a / search. <count> is for user-defined commands using the :command command, not for mappings using the :map command set.

Yes, I know that <count> is for commands. I mentioned because I
thought it would be possible to map a key to a user-defined command
with which I could capture the count. I wasn't aware of v:count, this
seems to be what I needed.Thank you!
e.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Loading...