1

I want to search and replace occurrences of

$this->close_db();

with

$this->stmt->close();
$this->database->close();

which occurs on lines 73-74 (with indentations).

What is a quick and simple way of doing this without plugins? I'm also too lazy to write out $this->close_db() and would like to simply reference it via one of the the lines it is on (line 89), without indentations.

Is there something like :%s/Trim@#89/#[73;;74]/g;AutoFormat (pseudocode)?

Update: Feel free to share methods that use non-obscure plugins or scripts too.

1 Answer 1

1

I don't think it could be simplified more without using mappings or writing specialized commands and/or functions:

" setup search pattern
:let @/ = '\V' . trim(getline(89))
" or you can input it interactively after the first :g/...
" with the help of :h c_ctrl-r_=

" get replacement text
:73,74y
" put (paste) with indent adjust
:g//normal! ]p
" delete old stuff
:g//d
1
  • Fixed a typo in comment. (p != "copy') :)
    – B Layer
    Commented Dec 4, 2019 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.