There is many times in my day to day work life that I need to operate on a specific function, things like highlighting or searching for a variable, but I have never managed to limit the scope of the edits/search.
Is there a way in vim to selectively say, find all references to $color
inside these sets of braces, or this fold etc. If possible, it would be ideal this is relatively generic, so that it could be applied to Editing/Replacing text.
As an Example:
$color = "#fff";
function PickColor () {
$color = "#bbb";
$newColors = ["#000", "#fbf", $color];
foreach ($newColors as $c) {
if ($c == "#fff") {
break;
}
}
}
$differentColor = $color;
This code is a relatively bad example, however, if I needed to replace all instances of $color how would one do this in the context of the function PickColor. As another example, using #
and *
You can go to the next instance of that text object, how would you limit the scope for the search to just this function (basically wrapping the search) opposed to the entire file which could span thousands of lines and losing your place, or incorrectly replacing something in another function that you shouldn't have?