0

I'm looking to capture the current class name (in java) using the % char - but in vimscript I want to push this string value into a variable

let objName = % throws an error currently so I'm looking for some help (vimscript newbie)

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
Dave Hill
  • 81
  • 1
  • 2
  • 6

1 Answers1

2

You are looking for expand().

   let objName = expand('%:t:r')
Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
  • 1
    It's worth emphasising that this will get the first part of the file-name (which should match the main class name in Java I believe). If, however, there's a private class locally defined in the same source file as the main one and the cursor is inside the private class, the class name returned will still be the file name. It would be possible (and not that hard) to get the name of the class in which the cursor is currently located, but that's another question... – DrAl Apr 18 '11 at 13:55
  • @dral: take a look at this [ctags functionname plugin](http://vim.sourceforge.net/scripts/script.php?script_id=610) too. I guess, this can be modified easily for java class names. – anishsane Aug 03 '16 at 04:03