Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Can you replace without also finding the next match? #1092

Closed
@michael-crawford

Description

@michael-crawford

Summary

I see a key mapping 'cmd-alt-e': 'find-and-replace:replace-next' to replace, then find the next match. I don't see a key mapping to replace (ONLY - don't move the cursor to the next match). If this feature does not exist, I'd like to have this added, such as 'cmd-alt-E': 'find-and-replace:replace' or 'cmd-ctrl-alt-e': 'find-and-replace:replace', so that if I know I'm replacing the last real match of an ambiguous pattern, but there may be other false matches further down the file, I don't have to reposition the view back to where the last replacement was done to continue editing.

Motivation

Earlier today I had to clone a section of YAML code then replace a single digit extension in numerous areas, such as One0 -> One8, Two0 -> Two8, ...; One1 -> One9, Two1 -> Two9, ... Many matches which changed one digit, so I was just switching between find-next and replace-next, as - due to the ambiguity - I was walking through matches one by one, often having to skip a false match. I had multiple sections where I had to repeat this far apart, with many sections where I would not want to accidentally replace this single digit in-between. Too much hassle and variance to try and use RegEx.

The problem which prompted a search for a "replace without attempting to find the next match" feature and perhaps key binding, was the last match in a known set, when I know changing from (for example, where there's a total of 16 places where I have to change this digit, all different) Sixteen0 -> Sixteen8, I want to replace 0 with 8, but then not move to the next 0 found arbitrarily down in the file. I'm forced to either hit Replace, then page up some unknown/unpredictable number of pages to get back to where the last change was made and where I needed to make other changes, or I have to manually overtype the character instead of pressing the Replace button or cmd-alt-e key combination.

It comes up a decent amount of times for me, so I was annoyed enough to check and see if there was some simple alternate key combination, like just cmd-ctrl-alt-e or cmd-alt-E, that would replace but then leave the cursor unmoved, same behavior as if there were no additional matches found.

What would be ideal, is if I could still hit the Replace button, but by also holding down the ctrl key, that would replace but stay put.

If there's some way to do this, I couldn't find it via Google search or looking through the keybinding code here.

Describe alternatives you've considered

  1. Hit Replace, then hit page-up to get back to the last replacement.
  2. Manually replace by overtyping the last known replacement, instead of using Replace button.

Both work, but disrupt workflow. It seems like one should be able to do this easily. It's a feature in many other editors I've used over the years.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions