sponsor Vim development Vim logo Vim Book Ad

ShowBlockName.vim : Show the name of the code-block (e.g. function) the cursor is in on the cmd line

 script karma  Rating 10/8, Downloaded by 1405    Comments, bugs, improvements  Vim wiki

created by
Gary Holloway
 
script type
utility
 
description
Display the name of the current "block" the cursor is in in the command-line
area (i.e., with vim's echo).

A "block" is context-sensitive, (e.g., function name, variable name if in an
initialization, type name if in a typedef, etc.)

NOTE: The only languages with specific support as-is are vim scripts, Perl, and C.  Support for other languages can be added by modifying the script with appropriate search patterns.

Typical use (.vimrc):
  au CursorHold * call ShowBlockName('quiet')

  " Show the name of the function we're in on the message line; pnuemonic [[
  map <silent> g[[ :call ShowBlockName()<CR>

  " Disable ShowBlockName (once); to prevent the CursorHold autocommand from
  " overwriting something in the command window (e.g., SyntaxAttr() output).
  map <silent> g]] :call ShowBlockName('OFF')<CR>


  " Tweak commands like [d so that they disable ShowBlockName so
  " it doesn't obliterate the output of this command.
  nnoremap [d :call ShowBlockName('[d')<CR>
  nnoremap [i :call ShowBlockName('[i')<CR>

NOTE:
This will NOT work if the start-of-block is the first line in a file.

THIS SCRIPT USES ShowLine ( vimscript #381 )
 
install details
I put it in my autoload directory (~/vim/autoload), so the function is automagically loaded as needed via an autocommand:

autocmd FuncUndefined * exe 'runtime autoload/' . expand('<afile>') . '.vim'
 

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
ShowBlockName.vim 1.6.1 2003-01-14 6.0 Gary Holloway Fixed typo.
ShowBlockName.vim 1.6 2002-08-15 6.0 Gary Holloway Removed extraneous '#' from perl function-matching pattern (thanks Christian ).
ShowBlockName.vim 1.5 2002-08-15 6.0 Gary Holloway Initial upload
ip used for rating: 54.204.178.31

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.
   
SourceForge.net Logo