1

I have a fair number of PHP classes source files that I can list using the command grep -r "class " * with each file containing the class <MyClass> pattern.

For example, one such file contains:

<?php

class NavlinkItem {

var $id; var $name; var $description; var $image; var $imageOver; var $url; var $blankTarget; var $language; var $templateModelId; var $navlinkId;

function NavlinkItem($id = '') { }

I would like to replace the function NavlinkItem pattern by the function __construct pattern.

The NavlinkItem pattern can be derived from the actual name of the system/navlink/NavlinkItem.php source file and I can get the it with expand('%:t:r')

I can store the NavlinkItem pattern in an a register let @a = expand('%:t:r')

I want to do a replace on the content of that register:

execute 's/function ' . getreg('a') . '/function __construct/'

The pattern seems to be found as it is highlighted in yellow.

But the command still errors and shows the E486: Pattern not found: function NavlinkItem message.

Destroy666
  • 12,350
Stephane
  • 205

1 Answers1

1

You need to use % symbol at the start of the regex if the whole document should be searched, rather than just the current line.

So execute '%s/function ' . getreg('a') . '/function __construct/' should work.

Destroy666
  • 12,350