Classical replace command looks like %s/old_pattern/new_pattern which is fine, but working with code or constructing complex search regular expression is not the best option. I'd like to present my own solution and looking for better options.

closed as unclear what you're asking by Ralf, jamessan, Naumann, Hotschke, Herb Wolfe Feb 24 at 18:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


Another workflow you can consider:

  1. Search for word using #, *, /, ? or :s/search_pattern.
  2. Make your change with cgn which change the next matched pattern.
  3. Pressing . will make the same change, for the next occurrence of the pattern. (so you can . . . ... to see each change, one at a time)
  • this is not portable to the spacemacs – A B Feb 10 '17 at 17:51
  • 2
    That's why I'm using Vim ;) – nobe4 Feb 10 '17 at 17:56

My current workflow looks like:

  1. Search for word using #, *, /, ? or :s/search_pattern

  2. Replace first occurrence using :s//new_pattern this works because empty search pattern in this command will use content of the search register "/ which contains the last search pattern in our case search_pattern

  3. Apply replace to all buffer using g& which is a shortcut to the :s//~/&

Suggestions are welcome.

Not the answer you're looking for? Browse other questions tagged or ask your own question.