Sibin P. Thomas wrote:
Hi all,
I am stuck in one of my scripting attempts!
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!
Several notes....
1. exe "/bios" might fail. You probably should use the search() function:
if search('bios')
...
endif
2. "bios" might be part of a word (example: symbiosis) and get found
when you don't want it to be.
Perhaps search('\<bios') would be better?
3. Why not do the search & substitute directly from ex?
/\<bios/s///
4. If for some odd reason you feel you absolutely must use visual mode
for this, then try
exe "norm! v//e\<cr>d"
Regards,
Chip Campbell