From: "A.J.Mechelynck" <[EMAIL PROTECTED]>
Subject: Re: How to insert text via script/function call ?
Date: Fri, 18 Aug 2006 18:05:13 +0200
> Meino Christian Cramer wrote:
> > From: "A.J.Mechelynck" <[EMAIL PROTECTED]>
> > Subject: Re: How to insert text via script/function call ?
> > Date: Fri, 18 Aug 2006 07:29:05 +0200
> >
> >> Meino Christian Cramer wrote:
> >>> Hi,
> >>>
> >>> I often need to place a header above a function defintion (C-source)
> >>> fpr documentational purposes.
> >>>
> >>> What I treid is to write a short function for vim, which dioes insert
> >>> the text skeleton -- but I did not find any already existing function
> >>> in the API which does this for me. With :i I got weird effects --
> >>> sure my fault, but... .
> >>>
> >>> How can I insert text via a script ?
> >>>
> >>> Kind regards,
> >>> mcc
> >>>
> >>>
> >>>
> >>>
> >>>
> >> If your text is in a file on its own, you can use ":r" with a line
> >> number (the number of the line after which to insert, or 0 for "before
> >> first line", or . for "after cursor line", or $ for "after last line";
> >> default is after cursor line) in the "range" position, i.e. just before
> >> the r. The file name comes as an argument at the end.
> >>
> >> Example (after line 5):
> >>
> >> 5r ~/template.txt
> >>
> >> If your text is in a register, you can use ":put" with a line number
> >> (again) in the range position and the register name (including ", which
> >> must be escaped as \", for the default register; or + for the system
> >> clipboard) after the ":put".
> >>
> >> Example (before cursor line):
> >>
> >> .-1put \"
> >>
> >>
> >> See
> >> :help :read
> >> :help :put
> >>
> >>
> >> Best regards,
> >> Tony.
> >>
> >
> > Hi Tony,
> >
> > thank you for your reply ! :)
> >
> > No, sorry...I was simply searching for a function call like
> >
> > printf( "This is my text!" )
> >
> > but instead of C and printing onto stdout it should be vim-script
> > and the text should go right at the current cursor position.
> >
> > Thats all.
> > No registers, no script magic, not extra files. Simply put a string
> > after the cursor into the text.
> >
> > Keep hacking!
> > mcc
> >
> >
> >
>
> (Untested):
> Characterwise:
> exe "normal aThis is my text!\<Esc>"
>
> Linewise:
> exe "normal oThis is my text!\<Esc>"
>
> If I didn't goof, you can paste one of the above lines straight into
> your script (via the clipboard).
>
>
> Best regards,
> Tony.
>
Hi Tony,
this works so far...with an unwanted sideeffekt:
Instead of
This is my text!
in my buffer I get
This is my text!<Esc>
in my text.
When using
exe "normal aThis is my text!"\<Esc>
instead, vim says in the commandline:
E121: Undefined variable: Esc
E15 Invalid expression: "normalaThis is my text"<Esc>
.
No way out ?
Kind regards,
mcc