I have a little class/function detector in my .vimrc displaying, in my statusline, the python class/function my cursor currently is inside of. I am currently trying to adapt it for C++ source files, and am running into a pretty simple (?) regex (?) problem.
My function essentially works as follows:
- find the line number of the previous match of
::, but ignorestdorcout:
let prev_class_line_number = search('\(std\)\@<!::\(cout\)\@!', 'bncW') - From that line, return the \word before
:::
let classname = matchstring(getline(prev_class_line_number), '\(\w\+\)::') For example, within the following code block:
void MyClass::setSomething(int input) { // ... } my function returns "MyClass" (yay!).
I however run into issues with this type of code:
std::vector<int> MyClass::doSomethingElse(){ // ... } where my function returns std instead of MyClass.
I spent a good amount of time getting my line-number-detection regexp to work (specifically, to not match std:: or ::cout), but I can't figure out how to get my second regexp to return 'MyClass'.
This looks like an incredibly simple problem and I'm sure I've been missing something. I searched into \zs/\ze, negative/positive lookahead/lookbehind, matchlist, but I haven't figured the right combination yet.
How do I extract the first word before a :: instance who is not std?
tl;dr: given the line std::foo bar::baz(), how can I return bar but not std?