map :%s/ to :%s/\v

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

map :%s/ to :%s/\v

Martin Trautmann
Hi all,

how do I map s/ to s/\v in order to use "very magic" regular expression
handling as a default?

I know that
   :nnoremap / /\v
does work, but I do not really understand the map variations.

Thanks,
Martin

--
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
|

Re: map :%s/ to :%s/\v

Benjamin Fritz


On Jul 8, 12:48 am, Martin Trautmann <[hidden email]> wrote:
> how do I map s/ to s/\v in order to use "very magic" regular expression
> handling as a default?
>
> I know that
>    :nnoremap / /\v
> does work, but I do not really understand the map variations.
>

This will work fine for normal mode. You probably also want to define
an xnoremap and an onoremap version.

See :help map-modes for more info.

Or were you missing the distinction between :nmap and :nnoremap, for
example? These two commands are different only in that the first will
expand mappings when executing (in your example, creating a recursive
mapping), whereas the second will not expand mappings, which is what
you want in this case.

--
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
|

Re: map :%s/ to :%s/\v

Tony Mechelynck
On 09/07/10 21:52, Ben Fritz wrote:

>
>
> On Jul 8, 12:48 am, Martin Trautmann<[hidden email]>  wrote:
>> how do I map s/ to s/\v in order to use "very magic" regular expression
>> handling as a default?
>>
>> I know that
>>     :nnoremap / /\v
>> does work, but I do not really understand the map variations.
>>
>
> This will work fine for normal mode. You probably also want to define
> an xnoremap and an onoremap version.
>
> See :help map-modes for more info.
>
> Or were you missing the distinction between :nmap and :nnoremap, for
> example? These two commands are different only in that the first will
> expand mappings when executing (in your example, creating a recursive
> mapping), whereas the second will not expand mappings, which is what
> you want in this case.
>

 From :help recursive-mapping

> [...] There is one
> exception: If the {rhs} starts with {lhs}, the first character is not mapped
> again (this is Vi compatible).
> For example: >
>    :map ab abcd
> will execute the "a" command and insert "bcd" in the text.  The "ab" in the
> {rhs} will not be mapped again.

so in this case the "nore" may be omitted, the mapping will still not be
recursive.


Best regards,
Tony.
--
Renning's Maxim:
        Man is the highest animal.  Man does the classifying.

--
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
|

Re: map :%s/ to :%s/\v

Martin Trautmann
On 10-07-09 23:01, Tony Mechelynck wrote:

> On 09/07/10 21:52, Ben Fritz wrote:
>>
>>
>> On Jul 8, 12:48 am, Martin Trautmann<[hidden email]> wrote:
>>> how do I map s/ to s/\v in order to use "very magic" regular expression
>>> handling as a default?
>>>
>>> I know that
>>> :nnoremap / /\v
>>> does work, but I do not really understand the map variations.
>>>
>>
>> This will work fine for normal mode. You probably also want to define
>> an xnoremap and an onoremap version.

I tried, but it does not work.

> so in this case the "nore" may be omitted, the mapping will still not be
> recursive.

So I tried also
   :nmap :%s/  :%s/\v

But it has no effect. Is there anything I have to escape?

Thanks,
Martin

--
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
|

Re: map :%s/ to :%s/\v

Tony Mechelynck
On 10/07/10 06:52, Martin Trautmann wrote:

> On 10-07-09 23:01, Tony Mechelynck wrote:
>> On 09/07/10 21:52, Ben Fritz wrote:
>>>
>>>
>>> On Jul 8, 12:48 am, Martin Trautmann<[hidden email]> wrote:
>>>> how do I map s/ to s/\v in order to use "very magic" regular expression
>>>> handling as a default?
>>>>
>>>> I know that
>>>> :nnoremap / /\v
>>>> does work, but I do not really understand the map variations.
>>>>
>>>
>>> This will work fine for normal mode. You probably also want to define
>>> an xnoremap and an onoremap version.
>
> I tried, but it does not work.
>
>> so in this case the "nore" may be omitted, the mapping will still not be
>> recursive.
>
> So I tried also
> :nmap :%s/ :%s/\v
>
> But it has no effect. Is there anything I have to escape?
>
> Thanks,
> Martin
>

try replacing the backslash by <Bslash>

Best regards,
Tony.
--
Dear Miss Manners:
        My home economics teacher says that one must never place one's
elbows on the table.  However, I have read that one elbow, in between
courses, is all right.  Which is correct?

Gentle Reader:
        For the purpose of answering examinations in your home
economics class, your teacher is correct.  Catching on to this
principle of education may be of even greater importance to you now
than learning correct current table manners, vital as Miss Manners
believes that is.

--
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
|

Re: map :%s/ to :%s/\v

Martin Trautmann
On 10-07-10 10:38, Tony Mechelynck wrote:
> On 10/07/10 06:52, Martin Trautmann wrote:
>> On 10-07-09 23:01, Tony Mechelynck wrote:
>>> On 09/07/10 21:52, Ben Fritz wrote:
>>>> On Jul 8, 12:48 am, Martin Trautmann<[hidden email]> wrote:

>>>>> I know that
>>>>> :nnoremap / /\v
>>>>> does work, but I do not really understand the map variations.

>> So I tried also
>> :nmap :%s/ :%s/\v
>>
>> But it has no effect. Is there anything I have to escape?

> try replacing the backslash by <Bslash>

No effect.

        :nnoremap / /\v
is ok,
        :nmap :%s/ :%s/<Bslash>v
is not.

Does map work for single characters only?

Thanks,
Martin

--
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
|

Re: map :%s/ to :%s/\v

Nikolay Aleksandrovich Pavlov
Ответ на сообщение «Re: map :%s/ to :%s/\v»,
присланное в 15:12:24 10 июля 2010, Суббота,
отправитель Martin Trautmann:

    noremap :%s/ :%s/\v
works as expected. Are you sure that you input :%s/ fast enough? Maybe defining S
command is better?
    command -nargs=1 -range S execute "<line1>,<line2>s".<q-args>[0].'\v'.
                                              \<q-args>[1:]

Текст сообщения:

> On 10-07-10 10:38, Tony Mechelynck wrote:
> > On 10/07/10 06:52, Martin Trautmann wrote:
> >> On 10-07-09 23:01, Tony Mechelynck wrote:
> >>> On 09/07/10 21:52, Ben Fritz wrote:
> >>>> On Jul 8, 12:48 am, Martin Trautmann<[hidden email]> wrote:
> >>>>> I know that
> >>>>>
> >>>>> :nnoremap / /\v
> >>>>>
> >>>>> does work, but I do not really understand the map variations.
> >>
> >> So I tried also
> >>
> >> :nmap :%s/ :%s/\v
> >>
> >> But it has no effect. Is there anything I have to escape?
> >
> > try replacing the backslash by <Bslash>
>
> No effect.
>
> :nnoremap / /\v
>
> is ok,
>
> :nmap :%s/ :%s/<Bslash>v
>
> is not.
>
> Does map work for single characters only?
>
> Thanks,
> Martin

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: map :%s/ to :%s/\v

Martin Trautmann
On 10-07-10 14:58, ZyX wrote:
> Ответ на сообщение <<Re: map :%s/ to :%s/\v>>,
> присланное в 15:12:24 10 июля 2010, Суббота,
> отправитель Martin Trautmann:
>
>      noremap :%s/ :%s/\v
> works as expected. Are you sure that you input :%s/ fast enough?

It does? I do not need the colon?

What do you mean by fast enough? I do not type this very fast since
these keys are spread and need some time to find (% is different on
various keyboard layouts).

> Maybe defining S
> command is better?
>      command -nargs=1 -range S execute "<line1>,<line2>s".<q-args>[0].'\v'.
>                                                \<q-args>[1:]

Hm, I may give this a try, but I wonder why the mapping does not work.

Thanks,
Martin

--
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
|

Re: map :%s/ to :%s/\v

Tony Mechelynck
On 10/07/10 21:21, Martin Trautmann wrote:

> On 10-07-10 14:58, ZyX wrote:
>> Ответ на сообщение <<Re: map :%s/ to :%s/\v>>,
>> присланное в 15:12:24 10 июля 2010, Суббота,
>> отправитель Martin Trautmann:
>>
>> noremap :%s/ :%s/\v
>> works as expected. Are you sure that you input :%s/ fast enough?
>
> It does? I do not need the colon?
>
> What do you mean by fast enough? I do not type this very fast since
> these keys are spread and need some time to find (% is different on
> various keyboard layouts).
>
>> Maybe defining S
>> command is better?
>> command -nargs=1 -range S execute "<line1>,<line2>s".<q-args>[0].'\v'.
>> \<q-args>[1:]
>
> Hm, I may give this a try, but I wonder why the mapping does not work.
>
> Thanks,
> Martin
>

"fast enough" means with less than 'timeoutlen' milliseconds (default
1000) between keypresses.

You may want to change the timeout settings: I use

        :set timeout timeoutlen=5000 ttimeoutlen=100

ttimeoutlen (in milliseconds) should be faster than your fastest typing
speed but slower than successive bytes sent for a single key by the
keyboard driver;

timeoutlen (also in milliseconds) should be slower than your slowest
typing speed but not too slow so that you can wait that long if you want
to "defeat" a mapping (and use the actual typed keys instead).

See
        :help 'timeout'
        :help 'timeoutlen'
        :help 'ttimeout'
        :help 'ttimeoutlen'


Best regards,
Tony.
--
Taxes are going up so fast, the government is likely to price itself
out of the market.

--
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
|

Re: map :%s/ to :%s/\v

Martin Trautmann
On 10-07-10 21:39, Tony Mechelynck wrote:

> On 10/07/10 21:21, Martin Trautmann wrote:
>> On 10-07-10 14:58, ZyX wrote:
>>> Ответ на сообщение <<Re: map :%s/ to :%s/\v>>,
>>> присланное в 15:12:24 10 июля 2010, Суббота,
>>> отправитель Martin Trautmann:
>>>
>>> Are you sure that you input :%s/ fast enough?
>>
>> What do you mean by fast enough? I do not type this very fast since
>> these keys are spread and need some time to find (% is different on
>> various keyboard layouts).


> "fast enough" means with less than 'timeoutlen' milliseconds (default
> 1000) between keypresses.
>
> You may want to change the timeout settings: I use
>
> :set timeout timeoutlen=5000 ttimeoutlen=100

Ah, thanks! Now it does work,
Martin

--
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