Vim Tips Wiki
No edit summary
 
Vim-rob (talk | contribs)
m (Just tried to tidy it up a bit from the automatic import and tried to make the explanation a little clearer, hope it helped)
Line 11: Line 11:
 
(Explanation below.) Add following in your ~/.vimrc
 
(Explanation below.) Add following in your ~/.vimrc
   
 
fun! ShowFuncName()
 
let lnum = line(".")
 
let col = col(".")
 
echohl ModeMsg
 
echo getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bW'))
 
echohl None
 
call search("\\%" . lnum . "l" . "\\%" . col . "c")
 
endfun
 
map f :call ShowFuncName() <CR>
   
   
 
Or if you need the "f" key just map the function to whatever you like, for example to use ",f" just change the last line above to read:
  +
 
map ,f :call ShowFuncName() <CR>
   
 
So, now if you have jumped into a lengthy function (via tag or search) you can see its name without any further scrolling, just press f and voila! I find this useful for code digging.
 
fun! ShowFuncName()
 
 
let lnum = line(".")
 
 
let col = col(".")
 
 
echohl ModeMsg
 
 
echo getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bW'))
 
 
echohl None
 
 
call search("\\%" . lnum . "l" . "\\%" . col . "c")
 
 
endfun
 
 
map f :call ShowFuncName() <CR>
 
 
 
 
 
 
Or if you need "f" key map to whatever you would like, for example ",f":
 
 
map ,f :call ShowFuncName() <CR>
 
 
 
 
 
 
So, now when you jumped inside of lenghty function (via tag or search) you can see its name without any further scrolling, just press f and voila! I find this useful for code digging.
 
   
   

Revision as of 07:35, 6 June 2007

Previous TipNext Tip

Tip: #1267 - Show current function name in C programs

Created: June 20, 2006 18:54 Complexity: intermediate Author: do1 --AT-- yandex . ru Version: 6.0 Karma: 56/25 Imported from: Tip#1267

(Explanation below.) Add following in your ~/.vimrc

fun! ShowFuncName() 
  let lnum = line(".")
  let col = col(".") 
  echohl ModeMsg 
  echo getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bW')) 
  echohl None 
  call search("\\%" . lnum . "l" . "\\%" . col . "c") 
endfun 
map f :call ShowFuncName() <CR> 


Or if you need the "f" key just map the function to whatever you like, for example to use ",f" just change the last line above to read:

map ,f :call ShowFuncName() <CR> 

So, now if you have jumped into a lengthy function (via tag or search) you can see its name without any further scrolling, just press f and voila! I find this useful for code digging.

Comments

call cursor(line,col)

vim at bertram dash scharpf dot de , June 21, 2006 3:07


Try this regexp for Java: echo getline(search("\\h\\+\\s\\+\\h\\+\\s*(.*)", 'bW'))

pmorant at mgtplc dot com , June 27, 2006 6:53


This works for Perl too. Won't it work for any language in which each line of a function body begins with whitespace (not just for C programmers)? E.g., PHP, shell scripts, vim scripts, etc.

emallove at yahoo dot com , July 9, 2006 13:09