How to run a search and replace with regex group capture substitution in VIM

Problem: you have a very large string to search and replace.
You want to use a regex for that (probably it is also the only way).
You want to use VIM.

To search across the whole file in VIM you need:

:%s

Then you want to add a regex, and since you want a group you have two options: escape all the parenthesis which I don’t want or use the special VIM very magic mode: \v.

Now you search for the group on the main part of the regex and substitute in the second:

:%s/\v(\w)/\1HELLO/g

This way you can export them all. In my case, I had a very large file (SQL Dump) where I had to convert binary values to use utf8mb4, so I wanted to run this:

:%s/\v(X'[^,\)]*')/CONVERT(\1 using utf8mb4)/g

Seeding a DB for testing purposes with Laravel and cross-references

  • Create a custom factory to fill up the data correctly
  • Call the factory with the right parameters depending on the status from the seeder
  • Fix the problems that are going to show up because of data structure.

Continue reading Seeding a DB for testing purposes with Laravel and cross-references