Thursday, March 24, 2005


While I've lots of stuff to post, I couldn't resist when I stumbled upon this SEXY Vim tip! I just couldn't wait to share this with you all. I know, this might be pretty naive for a seasoned Vi* user, but still just in case you don't have this! Just place this in your .vimrc.
" Get me the function name!
map _F ma[[k"xyy`a:echo @x

Ok, do you want me to explain it piece-meal... here it goes...
1. map _F
This will map key combination '_' followe by 'F' to whatever follows.
2. ma
Record/mark your current cursour location in the file into 'a'.
3. [[
Takes you to the start of the current function.
4. k
Move one line up.
Read/yank current line into register 'x'
Get back to where your cursour originally was, i.e. marked as 'a'
:echo @x
Echo the contents of reg 'x', which happens to be the function name!
This is the actual source of this tip!
Happy Vi*'ing!

Note: This won't work if you define your functions in a little different way!!!
In that case use
[[ to go to start of the function, read the name and press '' (two single quotes) to return to previous cursour location.

1 comment:

Suhas said...

That's the power of vi/vim. By the way you can create map / shortcuts and keep in your home (unix) in .exrc file. I think you know that. I have a sample file that can be used as block comments, block copy/paste, block uncomment,
Block copy/paste is very useful if you open 2 files and want to copy a buffer/no of lines from one file to another.

If you want my sample file , I can mail you!!!