Rename a variable in one function

Two functions in the same file share a throwaway name, tmp. The first one is about to grow, so its tmp should become total — every occurrence in that function, and none in the one below it, which keeps its tmp.

A language server’s rename would do this across the project, but the build here has no rename, and the job is deliberately narrower than a project-wide rename anyway: one function, three occurrences. Helix gives you two ways to keep a change inside a boundary.

Either way, the outcome is what counts: make the buffer match the target under the editor.

One route, if you want it

With the cursor anywhere in total_price, mif selects the function body. s, then tmp and Enter, leaves one cursor on each of the three tmps inside that selection. c deletes all three and drops into insert mode; type total and press Esc. The second function is untouched because it was never inside the selection.

Make the file match the target under the editor.

Any route counts — the buffer alone is judged.

Loading editor…

Target

fn total_price(items: &[Item]) -> u32 {
    let mut total = 0;
    for item in items {
        total += item.price * item.qty;
    }
    total
}

fn total_weight(items: &[Item]) -> u32 {
    let mut tmp = 0;
    for item in items {
        tmp += item.weight;
    }
    tmp
}