Vim Tips Wiki
mNo edit summary
 
(Change <tt> to <code>, perhaps also minor tweak.)
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  +
{{TipImported
 
{{review}}
 
{{Tip
 
 
|id=383
 
|id=383
  +
|previous=382
|title=a Map to jump to a subroutine/function from where it is called
 
  +
|next=384
|created=December 6, 2002 4:33
+
|created=2002
 
|complexity=basic
 
|complexity=basic
 
|author=zzapper
 
|author=zzapper
 
|version=6.0
 
|version=6.0
 
|rating=0/7
 
|rating=0/7
  +
|category1=
|text=
 
  +
|category2=
Hi
 
 
}}
 
When writing/debugging code you often want to jump from where a subroutine/function is called to where it actually is . Hitting the "*" key is frustrating if the sub/func is called many times. The following mapping solves the problem. (Notice how it can be altered for other lanaguages)
   
 
nmap gx yiw/^\(sub\<Bar>function\)\s\+<C-R>"<CR>
When writing/debugging code you often want to jump from where a subroutine/function is called to where it actually is . Hitting the "*" key is frustrating if the sub/func is called many times. The following mapping solves the problem. (Notice how it can be altered for other lanaguages)
 
   
 
Instructions: Place cursor over called function (normal mode) and type <code>gx</code>
   
 
==How it works==
 
;yiw : Yank inner work to un-named register
   
 
;/^\(sub\<Bar>function\)\s\+ : search for sub or function followed by 1 or more spaces
nmap gx yiw/^\(sub\&lt;bar&gt;function\)\s\+&lt;C-R&gt;"&lt;CR&gt;
 
   
 
;<C-R>" : Retrieve un-named register
   
 
;<CR> : Start Search
   
 
Information also included in [[VimTip305]].
Instructions: place cursor over called function (normal mode) and type gx
 
 
 
 
 
 
How it works:
 
 
yiw : Yank inner work to un-named register
 
 
/^\(sub\&lt;bar&gt;function\)\s\+ : search for sub or function followed by 1 or more spaces
 
 
&lt;C-R&gt;" : Retrieve un-named register
 
 
&lt;CR&gt; : Start Search
 
 
 
 
 
 
(also included in [[VimTip305]] )
 
}}
 
 
== Comments ==
 
Take a look at [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:tags-and-searches}} :help tags-and-searches]
 
   
  +
==References==
  +
*{{help|tags-and-searches}}
  +
*{{help|tag=g%5D|label=g&#93;}}
   
 
==Comments==
'''Anonymous'''
 
  +
What language is this supposed to work in? Basic??
, December 6, 2002 9:02
 
  +
:Probably perl, which also uses sub for functions
 
----
 
----
  +
I suggest to modify mapping:
g]
 
  +
nmap gx mryiw/^\(sub\<Bar>function\)\s\+<C-R>"<CR>
   
  +
thus allowing reverse jump by typing `r
'''Anonymous'''
 
, December 16, 2002 23:33
 
 
----
 
----
  +
I think this would be much better accomplished using Vim's excellent Ctags interface. {{help|ctags}}. Exuberant Ctags has support for Perl. --[[User:Fritzophrenic|Fritzophrenic]] 20:03, 18 February 2009 (UTC)
<!-- parsed by vimtips.py in 0.316099 seconds-->
 

Revision as of 05:27, 13 July 2012

Tip 383 Printable Monobook Previous Next

created 2002 · complexity basic · author zzapper · version 6.0


When writing/debugging code you often want to jump from where a subroutine/function is called to where it actually is . Hitting the "*" key is frustrating if the sub/func is called many times. The following mapping solves the problem. (Notice how it can be altered for other lanaguages)

nmap gx yiw/^\(sub\<Bar>function\)\s\+<C-R>"<CR>

Instructions: Place cursor over called function (normal mode) and type gx

How it works

yiw
Yank inner work to un-named register
/^\(sub\<Bar>function\)\s\+
search for sub or function followed by 1 or more spaces
<C-R>"
Retrieve un-named register
<CR>
Start Search

Information also included in VimTip305.

References

Comments

What language is this supposed to work in? Basic??

Probably perl, which also uses sub for functions

I suggest to modify mapping: nmap gx mryiw/^\(sub\<Bar>function\)\s\+<C-R>"<CR>

thus allowing reverse jump by typing `r


I think this would be much better accomplished using Vim's excellent Ctags interface. :help ctags. Exuberant Ctags has support for Perl. --Fritzophrenic 20:03, 18 February 2009 (UTC)