Meino Christian Cramer wrote:
From: "A.J.Mechelynck" <[EMAIL PROTECTED]>
Subject: Re: Terminating search in function
Date: Sun, 22 Oct 2006 11:00:14 +0200

Meino Christian Cramer wrote:
From: "A.J.Mechelynck" <[EMAIL PROTECTED]>
Subject: Re: Terminating search in function
Date: Sun, 22 Oct 2006 09:33:01 +0200

Meino Christian Cramer wrote:
Hi,

 I wrote this snippet:

"--------------------------------------------------------------------------------
fun! Ffunchdr()
    let date = strftime( "%F" )
    
put='/*-----------------------------------------------------------------------------*/'
    put='/**'
    put=' * desc'
    put=' *'
    put=' *'
    put=' *'
    put=' * Created: ' . date . '
    put=' *'
    put=' * parameter:
    put=' * parameter:
    put=' * parameter:
    put=' * parameter:
    put=' * parameter:
    put=' *'
    put=' * result 0 - Success, -1 - Failure'
    put=' *'
    put=' */'
    ?desc
endfun
command! Funchdr :call Ffunchdr()



This should give nme the header comment for function definitions in C.
My problem seems to be the "?desc" command at the end.
It /should/ move the cursor onto the "desc" keyword right in the
beginning of the comment block.

But it move the cursor to here:

* desc ^
          |
          cursor position

My """analysis""" (a too big word...) of the problem is: "?" is still
waiting for input. I tried


    ?desc<CR>

instead, but now "?" tries to find "desc<CR>" literally and did not
find it.

There seem to be an exception of the "type the commands as you would
do normally"-rule here...but what is the rule to recognize that the
current situation is an exception and what is the solution?

Thank you very much in advance for any help ! :)

Have a nice weekend!
mcc


What you're using is a "searching range" (as in ":?desc" from the keyboard). It positions the cursor on the first nonblank in the matched line.

To use a "search command" (as in "?desc" from the keyboard) in an Ex-command line, use ":normal":

        normal ?desc

see
        :help :range
        :help :normal


Best regards,
Tony.

Hi Tony,

 :O) thank you,Tony !:O)

execute "normal ?desc\<CR>" will do the job and it seems, that a final

 execute "normal cw" on the found "desc" cannot be done correctly,
 since the command is not finished (which it should eb according to
 the :help normal text).

 Have a nice weekend!
 mcc

"normal cw" is not finished since the c (change) commands needs to be told _to_ what you want to change the replaced word. What you can do instead (IIUC) is "normal diw" (delete inner word) followed by "startinsert!". Note that "startinsert[!]" only makes sense as the last statement of the script (because insert-mode will be delayed until then).

Have a nice weekend too.


Best regards,
Tony.


Hi Tony,

 ...the "normal diw"+startinsert!-trick works nice !
 Thanks a lot -- such little helpers like the now
 finally working Function-header-function() are the
 _real_ stuff helping one to speed up the daily work --
and of course the helping hands, which make the helper-function work ... :O)

 Happy VIMming!
 mcc





BTW, instead of all those "put" statements, wouldn't it be simpler to have your template as a separate file, and use ":r filename" to insert it after the cursor?


Best regards,
Tonoy.

Reply via email to