Hi,

Jeri Raye wrote:
> 
> Can you use the position of a word in a search and replace as an argument
> 
> For example
> 
> if the line has the word INPUT in it, then the last word should have
> () around it
> 
> So:
> 
> start:     INPUT s1 , s2
>             INPUT s3 , s4
> 
> must become
> 
> start:     INPUT s1 , (s2)
>             INPUT s3 , (s4)

  g/\<INPUT\>/s/\(.*\)\(\<\w\+\>\)/\1(\2)/

or

  g/\<INPUT\>/s/.*\zs\(\<\w\+\>\)/(\1)/

do this. The :global-command restricts the following substitution to
lines containing the word INPUT. The :substitute-commands first try to
match as many characters as possible in a line, but then they backtrack
to be able to match the right-most single word. The first command then
replaces everything that was matched with the part before the word and
the word itself in parentheses. The second command uses \zs to reset the
start of the match and replaces only the word with itself in parentheses.

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

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

Reply via email to