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.


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)
| improve this answer | |
  • 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.

| improve this answer | |

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