Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Display the name of the function you are editing
(section)
Back to page
Edit
Edit source
View history
Talk (0)
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
Anti-spam check. Do
not
fill this in!
==Comments== I implemented another way to look for the name of the current function in c_stl.vim ([http://hermitte.free.fr/vim/ressources/vimfiles/ftplugin/c/ http://hermitte.free.fr/vim/ressources/vimfiles/ftplugin/c/]). However the search is very slow and time consuming when we try to guess the current function when there is no current function. I guess using <code>:normal [[</code> could have been more effective. Using the preview windows instead of the statusline could be an option to think about (see previousWord.vim in the same place). ---- I have modified the code from above to cater for test case below. <pre> function! FunctionName() "set a mark at our current position normal mz "while foundcontrol == 1, keep looking up the line to find something that "isn't a control statement "find the previous '{' and get the line above it "if the line matches a control statement, set found control to 1 so "we can look farther back in the file for the beginning of the "actual function we are in let foundstr = "" let strArrow = "" let strList = ["while", "for", "if", "else", "try", "catch", "case"] let foundcontrol = 1 while (foundcontrol) "find the { in this {...} normal [{ normal k0 let tempstring = getline(".") let foundcontrol = 0 for item in strList let foundstridx=match(tempstring,item) if(foundstridx >= 0) let foundstr = strpart(tempstring, foundstridx, 30) . strArrow . foundstr let tempstring = "" let strArrow = " @@@ " let foundcontrol = 1 break endif endfor if (foundcontrol == 0) let foundstridx = match(tempstring, "(") if(foundstridx >= 0) "we may found a function "go back to where our original cursor located normal `z let tempstring = tempstring . strArrow . foundstr return tempstring else "may not be a function, just a inner block here let foundcontrol=1 endif endif endwhile return tempstring endfunction </pre> Test case: Try place at "hihi" and "hoho" and call the function <pre> function() { haha { hoho } case huhu: { hihi } } </pre>
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Follow on IG
TikTok
Join Fan Lab