J-Win
J-Win

Reputation: 1492

Vim function to check if text exists in a file

I would like to see if something already exists in the current file (e.g. a certain import) by making a custom Vim function. Just an idea, is it possible to use the response from searching for something with /?

Upvotes: 2

Views: 738

Answers (1)

Alexander Batischev
Alexander Batischev

Reputation: 820

You can use search(). Specifying 'nw' in flags (second argument); n will ensure the cursor stays in place, and w ensures you search the whole file, not just a portion of it. You can then check the function's result; if it's non-zero, then something matched your pattern.

Upvotes: 4

Related Questions