I'm working on applying doctrine/coding-standard on doctrine/orm, and I would like to work smarter.
I would like to search occurences of
/** * @Id * @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ and replace them with
/** * @var int * @Id * @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ My current grepprg is rg\ --vimgrep\ --smart-case, so I tried :gr '/\*\*\n \* @Id\n \* @Column.*"integer"\)\n \* @GeneratedValue.*\n \*/' --multiline tests/ (I'm planning to use :cdo … after that, which should be easy enough.
It finds the occurences alright, but it formats them in such a way that each line of the matched block is considered a separate occurence, like this:
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:109:5: /** tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:110:5: * @Id tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:111:5: * @Column(type="integer") tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:112:5: * @GeneratedValue(strategy="AUTO") tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:113:5: */ tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:189:5: /** tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:190:5: * @Id tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:191:5: * @Column(type="integer") tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:192:5: * @GeneratedValue(strategy="AUTO") tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:193:5: */ That will not work well with :cdo I'm afraid. Maybe it would work if rg '/\*\*\n \* @Id\n \* @Column.*"integer"\)\n \* @GeneratedValue.*\n \*/' --multiline tests/ --vimgrep printed the following instead:
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:109:5: /** * @Id * @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php:189:5: /** * @Id * @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ How would you do such a complicated search and replace?
grepis able to do that: stackoverflow.com/questions/2686147/…:grepa single-line patter, and then do:cdo call F()whereFexamines the next few lines for a match and then applies the transformation. The-rtrick is nice though.