The context :
Suppose I want to delete the string "bio" from the following line "The
biosphere is huge" and I want to do it in this way ->
/bios<CR>
v<CR>
//e<CR>
d<CR>

Now I want to do the same thing, but conditionally...basically I want to use
the :if construct.
I tried -> :if (@0=~"something") | exe "/bios" | exe "normal v" | exe "//e" |
endif
This where I am stuck; I am not able to reproduce the effect of //e<CR>
through the :if construct.

In this case I get the error "e481: No range allowed" and if I try -> exe
"normal //e" it just stays in visual mode doing nothing.

Can anyone help me out here? This is going to play a huge part in most of my
scripts!

It seems like you're trying to retrofit a solution to one problem to a different class of problems. The old "when all you've got is a hammer, everything looks like a nail" adage. :)

It sounds like the regexp

        \<bio\zes

can be used in something like

        :s/\<bios/s/gc
        :s/\<bio\zes//gc

(with or without that "c" or "g" flag) The same can be done using a call to the substitute() function if needed in a script. To do what you describe above, you could do something like

        :/\<bios/s//s

which will

/\<bios/     search for "bios" at the beginning of a word
s//             replace the previous find ("bios")
s               with just an "s"

Or alternatively:

        :/\<bio\zes/s///

/\<bio               search for "bio"
\ze             end the match here (for replacement purposes,
                but there's more following for a match)
s               the "s" of context after "bio"
s//             substitute the last match (the "bio" bit)
                with nothing

Perhaps with more details on what you're trying to do, the list can provide more targeted responses. To address the problems you were experiencing, I suspect that you need to include either a "\r" or "\n" in your "normal" command as the act of doing the search (as you would actually hit <enter>). However, I would recommend doing the process from Ex commands as they're a little less convoluted.

Just a few ideas,

-tim


Reply via email to