bairui

Current Vim Function name in statusline

Dec 8th, 2011
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.55 KB | None | 0 0
  1. " If the cursor is currently within a function body, show
  2. " the function name in the statusline.
  3.  
  4. function! VimCurrentFunction()
  5.   let fpos = search('^\s*fu', 'bnW')
  6.   if fpos != 0
  7.     let epos = search( '^\s*endf', 'bnW')
  8.     if (epos == 0) || (epos < fpos) || (epos == line('.'))
  9.       return ', ' . matchlist(getline(fpos), 'function!\?\s*\(\w\+\)')[1]
  10.     else
  11.       return ''
  12.     endif
  13.   else
  14.     return ''
  15.   endif
  16. endfunction
  17.  
  18. set statusline=%f%m%r%h%w\ [%n:%{&ff}/%Y]%=[0x\%04.4B][%03v][%p%%\ line\ %l\ of\ %L\%{VimCurrentFunction()}]
  19.  
Advertisement
Add Comment
Please, Sign In to add comment