sponsor Vim development Vim logo Vim Book Ad

findfuncname.vim : Find the name of the function you are editing

 script karma  Rating 24/17, Downloaded by 2043  Comments, bugs, improvements  Vim wiki

created by
Alex Esplin
 
script type
utility
 
description
This is similar to the tip I posted previously, except I made a few fixes and made it self-contained as a plugin.

The script contains a function called 'FunctionName()' that returns the name of the function you are currently working in.  This is handy if you got there through a search, or are in a large function or small screen/window and can't see the function's name.  

This on-command (I've seen some that constantly display in the status line) function uses a search pattern to search for a pattern that matches every function declaration I've tried in C, Objective-C, C++, Perl, and Python with the caveat that the function declaration must start on the first character of the line.  I'll fix this one of these days, since Java files will break on that particular point.

 
install details
download the script and place it in your plugin directory, or make sure that your .vimrc sources the script wherever you have saved it.

Add the following to your .gvim or .vimrc:
map \func :echo FunctionName()<CR>

Now, typing \func displays the line number and declaration of the name of the function I am editing in.  
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
findfuncname.vim 3.6 2010-10-20 7.0 Alex Esplin Silently replace if a function with the same name is already loaded.
findfuncname.vim 3.5 2009-09-24 7.0 Alex Esplin Updated the regex to catch commas (if argument list is split from the declaration line onto succeeding lines) or closing parens (if argument list is all on the declaration line).
findfuncname.vim 3.4 2009-09-24 7.0 Alex Esplin Fixed a bug with the filename matching when checking for Python files. Made the regex for C-like function declarations a little more specific.
findfuncname.vim 3.3 2009-09-24 7.0 Alex Esplin Fixed to detect if the current file ends with .py and makes it look for the most recent 'class name:' or def 'func():' statement.
findfuncname.vim 3.2 2009-03-29 6.0 Alex Esplin minor change to allow for empty space at the end of the declaration line
findfuncname.vim 3.1 2009-02-25 7.0 Alex Esplin Small change to allow for code with the curly brace on the line below the function declaration.
findfuncname.vim 3.0 2009-02-24 7.0 Alex Esplin Major change to search pattern.

Actually works for most C, C++, Python, and Perl programs with functions.

Relies on function starting in the first column, so Java files will have issues, I'll fix this soon...
findfuncname.vim 2.0.1 2009-01-20 7.0 Alex Esplin minor comment/documentation change
findfuncname.vim 2.0 2009-01-20 7.0 Alex Esplin Major overhaul using a backwards-searching regular expression that seems to dodge control statements (if,else,else if,for,while, etc...) and catch most function declarations.
findfuncname.vim 1.0 2006-08-03 7.0 Alex Esplin Initial upload
ip used for rating: 3.14.141.228

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github