On 07/06/10 04:04, ShayAllen wrote:

OK. I've got a text file that looks like this:

pre

and a function that looks like this:

function! Test_func()
   exe "normal ggVGyGobottom\<Esc>pVG"
   '<,'>s/pre/post/
endfunction

The first line leaves me with a file that looks like this:

pre
bottom
pre

with the bottom "pre" selected. At this point I can run the second line as a
separate command to get:

pre
bottom
post

But, when I include the second line in the function and run the function as
a whole, I get:

post
bottom
pre

I'm baffled.

I think you could replace that long and complex normal command by ex-commands. Let's see:

gg      go to top
V       set linewise visual
G       go to bottom
y       yank visual selection (whole file)
o       open new line below, start insert mode
bottom  "bottom"
Esc     go to Normal mode
p       put after
V       start linewise visual
G       go to bottom
'<,'>s/pre/post
the '<,'> is implicit I think. If you use it like this, Vim will fill it to (I think):

        :'<,'>'<,'>s/pre/post

but is this valid?


So, let's try (untested):

        $put ='bottom'  " add the word 'bottom' below the last line
        $mark '         " mark the current last line
        1,$-1copy $     " copy all lines except the (new) last one
                        " to below the last line
        " the following starts with two apostrophes, not one dblquote
        ''+1,$s/pre/post " starting after the added "bottom" line,
                        " to the end, replace 'pre' by 'post'
                        " (at most once per line)

see
        :help range
        :help :put
        :help quote=
        :help :mark
        :help :copy


Best regards,
Tony.
--
No letters of the alphabet were harmed in the creation of this message.

--
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 via email to