Reputation: 7794
I'm trying to add a regex for ctrlp-funky for typescript functions but it is catching if and switch.
How do I modify this regex to not include words that are if
or switch
or function calls containing {}
.
\v\s*\w+\s*\(.*\{
It should be able to match these
greet() {
ifExists() {
public static greet(a: any) {
but should exclude. (notice the spaces and {
inside (
).
if (x) {
if(x) {
switch (x) {
helloworld({a: null});
Upvotes: 1
Views: 332
Reputation: 693
Though I have no idea you work with what kind of files, you could use post_extract_hook which is an undocumented, actually. I guess what you want to do is similar to java's one below: https://github.com/tacahiroy/ctrlp-funky/blob/master/autoload/ctrlp/funky/ft/java.vim#L22
Pull requests are always appreciated :)
Upvotes: 0
Reputation: 89171
This should work a little better:
\v\s*<(for>|if>|switch>|while>)@!\w+\s*\(.{-}\)\s*\{
<
and >
are word boundaries. They will match at the left and right edge of a word.@!
is a negative look-ahead. It will match the the content does not follow.{-}
is a lazy repeat, zero or more times. Similar to *
, but will match as little as possible.It will match any function-call pattern that does not match a keyword.
It is not perfect, since it does not match nested parentheses properly. That is not possible with just regular expressions in vim. For example:
foo(lock(foo) { })
Upvotes: 1