search from inside a function

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

search from inside a function

meino.cramer
Hi,

 I fear this is a stupid question, but I currently have
 no idea to answer it myself...
 Inside a funtion definition I want to execute a search
 with a fixed search pattern including regexp portions.

 When I want to execute a command from inside a function
 definition I would do a
    :<command>
 and the ':' would switch to command mode.

 But
    /<string>
 inside a function definition looks more like the start
 of pattern as such and not like the instruction to
 search something to me...

 confused...

 Thank you very much in advance for any help!
 
 Have a nice weekend!
 Best regards,
 mcc

--
Please don't send me any Word- or Powerpoint-Attachments
unless it's absolutely neccessary. - Send simply Text.
See http://www.gnu.org/philosophy/no-word-attachments.html
In a world without fences and walls nobody needs gates and windows.

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: search from inside a function

Tim Chase
[hidden email] wrote:

>  Inside a funtion definition I want to execute a search
>  with a fixed search pattern including regexp portions.
>
>  When I want to execute a command from inside a function
>  definition I would do a
>     :<command>
>  and the ':' would switch to command mode.
>
>  But
>     /<string>
>  inside a function definition looks more like the start
>  of pattern as such and not like the instruction to
>  search something to me...

It ("/") is a valid Ex command:

   function! FindFoo()
     /foo
   endfunction

which you can read briefly about at

   :help :/

and with no real help-anchor:

   :help :bar
or
   :help cmdline.txt

where you'll have to search for this bit of help:

   Because of Vi compatibility the following
   strange commands are supported:
    :| print current line (like ":p")
    :3| print line 3 (like ":3p")
    :3 goto line 3

most importantly the "goto line 3" applies to any
range-specifier, not just a fixed line-number.  I'm not sure how
I stumbled across this, except perhaps remembering how it worked
in "ed" and just trying it.

Anyways, that means you can validly do things like

   function! Find2ndLineAfterFoo()
      /foo/+2
   endfunction

At least that's my preferred way.  One could also reach for
something like

   call search(...)

but my preference is just my old-fogey nature showing through :)

Hope this helps,

-tim


--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: search from inside a function

meino.cramer
Tim Chase <[hidden email]> [10-01-23 05:08]:

> [hidden email] wrote:
> > Inside a funtion definition I want to execute a search
> > with a fixed search pattern including regexp portions.
> > When I want to execute a command from inside a function
> > definition I would do a
> >    :<command>
> > and the ':' would switch to command mode.
> > But     /<string>
> > inside a function definition looks more like the start
> > of pattern as such and not like the instruction to  search something
> >to me...
>
> It ("/") is a valid Ex command:
>
>   function! FindFoo()
>     /foo
>   endfunction
>
> which you can read briefly about at
>
>   :help :/
>
> and with no real help-anchor:
>
>   :help :bar
> or
>   :help cmdline.txt
>
> where you'll have to search for this bit of help:
>
>   Because of Vi compatibility the following
>   strange commands are supported:
>   :| print current line (like ":p")
>   :3| print line 3 (like ":3p")
>   :3 goto line 3
>
> most importantly the "goto line 3" applies to any range-specifier, not
> just a fixed line-number.  I'm not sure how I stumbled across this,
> except perhaps remembering how it worked in "ed" and just trying it.
>
> Anyways, that means you can validly do things like
>
>   function! Find2ndLineAfterFoo()
>      /foo/+2
>   endfunction
>
> At least that's my preferred way.  One could also reach for something
> like
>
>   call search(...)
>
> but my preference is just my old-fogey nature showing through :)
>
> Hope this helps,
>
> -tim
>
>
> --
> You received this message from the "vim_use" maillist.
> For more information, visit http://www.vim.org/maillist.php
>

Hi Tim,

this helps a lot, thank you very much !:)

Have a nice weekend!
Best regards,
mcc

--
Please don't send me any Word- or Powerpoint-Attachments
unless it's absolutely neccessary. - Send simply Text.
See http://www.gnu.org/philosophy/no-word-attachments.html
In a world without fences and walls nobody needs gates and windows.

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php