galaapples
galaapples

Reputation: 205

in vi, how to search and append something?

I have a bash file

#!/bin/bash
curl '/entry/point.json?name=ab'
echo 1
sleep 60
curl '/entry/point.json?name=bc'
echo 2
sleep 60

and so on. I'd like to append

|jsonpp

after each curl command. How am I supposed to do that in VI? Such as

:%s/curl/?????/g

Upvotes: 1

Views: 70

Answers (2)

sehe
sehe

Reputation: 393174

1. :global

:g/curl/norm A|jsonpp

would be my favourite


2. 'interactive' repeats:

  • 'Highlight' curl (using * or #)
  • A|jsonppEsc
  • repeat at leisure: n. n. n. ...

3. bash functions

Alternatively,

#!/bin/bash
function curl()
{
    /usr/bin/curl "$@" | jsonpp
}

curl '/entry/point.json?name=ab'
echo 1
sleep 60
curl '/entry/point.json?name=bc'
echo 2
sleep 60

Upvotes: 1

yan
yan

Reputation: 20982

:%s/^\(curl .*\)$/\1 | jsonpp/g

Upvotes: 0

Related Questions