Saturday, July 31, 2010

Re: Searching for single character without anything around it , possible ?

On 31/07/10 10:34, Aaron Lewis wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
> I've remembered that some implementations of RegExp has a '\b' sign ,
> e.g \bi\b means an character `i' without anything around it , does vim
> support it ?
>
> :help regular-expression seems to have that expression , but no much
> documents about it.
>
> Consider this: int i = 0 ; i< numOfServ ; i ++
> And i'd like to replace the single `i' with j , so i tried s/\bi\b/j/g
> , not working ? Or maybe something else , anyone could help ?
>
> Thanks in advance !

In Vim regexps, \b means a backspace character: probably not what you
want; but \< means start-of-word and \> means end-of-word so /\<i\>/
would find the letter i (which is in 'iskeyword') with no other
'iskeyword' character next to it. Before it could be the start of the
line, or a space, a tab, a comma, a parenthesis, etc., or anything not
in 'iskeyword'; after it could be the end of the line, a space, etc.

If you want i alone on its line, then /^i$/ would match it ( ^ is
begin-of-line and $ is end-of-line). If you want either a space, tab, or
begin-of-line before, and a space, tab, or end-of-line after, then you
could match with /\%(^\|\s\)\zsi\ze\%(\s\|$)/ The latter can be
simplified to /\_s\zsi\ze\_s/ if your "lone i" can be neither the first
character of the file nor the last character on a file with no
end-of-line on its last line.

See :help pattern-overview -- the list continues until the next line of
equal signs across the page.


Best regards,
Tony.
--
It is illegal to rob a bank and then shoot at the bank teller with a water
pistol.
[real standing law in Louisana, United States of America]

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

No comments:

Post a Comment