Wikia

Vim Tips Wiki

Changes: Jump to a function from where it is called

Edit

Back to page

(Comments: better to use Ctags)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 3: Line 3:
 
|previous=382
 
|previous=382
 
|next=384
 
|next=384
|created=December 6, 2002
+
|created=2002
 
|complexity=basic
 
|complexity=basic
 
|author=zzapper
 
|author=zzapper
Line 15: Line 15:
 
nmap gx yiw/^\(sub\<Bar>function\)\s\+<C-R>"<CR>
 
nmap gx yiw/^\(sub\<Bar>function\)\s\+<C-R>"<CR>
   
Instructions: Place cursor over called function (normal mode) and type <tt>gx</tt>
+
Instructions: Place cursor over called function (normal mode) and type <code>gx</code>
   
 
==How it works==
 
==How it works==

Latest revision as of 05:27, July 13, 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 worksEdit

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.

ReferencesEdit

CommentsEdit

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)

Around Wikia's network

Random Wiki