Thursday, August 4, 2011

Re: A few questions about :append and ex

On 08/04/2011 03:16 AM, ranousse@gmx.com wrote:
> 1) If I understand right, :append is used this way
> :append
> line1
> line2
> .
> and . means end, in a similar way as
> cat<<EOF
> line1
> line2
> EOF
>
> What could I do if I want to insert a line containing only a point.
> I don't really need this but I'm curious ;-)

As best I can tell, you can't. I suppose, if you were really
interested and forced to use :a, then I'd enter one extra
character and then :s it away:

:a
line1
.!
line3
.
:-2s/.$

(the last line goes back 2 lines and removes the last character,
i.e. the "!". Slightly confusing as it uses "." to mean something
other than the period in question). An alternative is to use
:put (see below)

> 2) With the cat example above, it's possible to write things like
> cat<<EOF
> $var
> line2
> EOF
>
> Has vim something similar (by default not it seems)?
> And is there a better solution than
> :execute "normal o" . var . "\nline2"
> to handle this case?

For such an example, I'd use a combination of :put with the
expression register, which takes a list:

:put=[var, 'line2', '.', 'that was a line with 1 period']

which pretty cleanly seems to do what you want for both cases.

> 3) I've just read in the documentation that if 'cpo' option doesn't
> contain C,
> :append
> a
> \b
> .
> would write
> ab
> because the \ is understood as line continuation.
> I have cpo=aABceFs (the default configuration, on my computer)
> But I obtain
> a
> \b
> (actually C or not does not seem to change anything, do I miss
> something?)

I believe this only takes place when you :source the file, not
entering them interactively. There's a sideways mention of this at

:help line-continuation

> 4) and a last one about ex use
> It seems that one uses ex in the following way
>
> ex file<<EOF
> %s/pattern/replace/g
> w
> EOF
>
> a) In this case, I do not write wq or x at the end but w and it seems
> to work. Is it cleaner (necessary ?) to add :q as last line, or is it
> implicitely added.

I don't know about "necessary", but I tend to prefer explicit
commands. You can either use

wq

or

x

instead of just "w"

> b) Has ex an option such as -s (meaning string) so that a sh user
> could write the previous example this way
> sh -s '%s/pattern/replace/g | w' file
> (bash or zsh users can already use<<< for this, but I need sh in my
> case). What I don't like about ex ...<<EOF, is that it looks weird in
> an indented script (the here document must be stuck to the left margin it
> seems)

I'm not sure I follow this example...you never invoke
vim/vi/ed/ex to edit the stream. And for the change in question,
unless your "pattern" includes vim-specific tokens, I'd be
tempted just to use sed.

-tim

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