I was refactoring a bunch of imports. We use remix-utils
in our Remix codebase at work and we have been on v4 for quite a long time. This version exported some utility functions for http responses
Latest versions do not export these functions anymore, so I replicated them in a utility file.
I wish I could’ve just find-and-replace-all, but some of the imports were mixed with other non-http imports!
The flow was:
- Grep for
remix-utils
imports - Replace the import with
~/utils/http.server
- Save the buffer
- Close the buffer
- Repeat
I cannot automate the grep
’ing, but I can for sure automate the rest. Finally, the time to learn about Vim macros has come to save my sanity.
First, start recording the macro pressing q
. Then, press the key you want to use a register. I chose j
:
Second, record the actions. I have a remap on <leader>bd
to delete the buffer:
This will:
- Change the text inside the
'
quotes to~/utils/http.server
- Save the buffer
- Close the buffer
And to finish, stop recording the macro pressing q
again.
Now I just had to play the macro with @j
and it would repeat the whole sequence 🤯. I saved so much time with this!