0

Say I want to turn this:

find(vec_a.begin(), vec_a.end(), c)

into this:

find(vec_b->begin(), vec_b->end(), c)

That's what I just wanted to do, so I tried this (commands separated by commas):

/vec_a, e, rb, a, right, backspace, ->

and it did what I wanted it to do which is replace vec_a. with vec_b->. Only problem is when i did n ciw . the . only puts -> and not vec_b->. How should I accomplish replacing individual instances of vec_a. with vec_b->?

  • you probably want to look at the search & replace command: :s/vec_a/vec_b/g look at :help :s for more info – Doktor OSwaldo Mar 17 '17 at 6:54
  • 1
    Eventually recording a macro would be useful here. See :h complex-repeat – grodzik Mar 17 '17 at 13:59
  • @DoktorOSwaldo I only wanted to replace a few occurences of many. – Accumulator Mar 17 '17 at 16:55
  • Another approach: /vec_a/e searches for "vec_a" but places cursor at the end of the searched string. Next you do 2sb-> followed by <Esc> which substitutes 2 characters with "b->". From there n will match next searched item and . will substitute just what you need. – Roflo Mar 17 '17 at 17:33
0

Search for the string you want to replace (/vec_a\.), then use cgn to replace the string.

You can then replace other instances of vec_a. by typing . (or n to skip).

If you prefer, vim-visual-star-search let's you select vec_a. visually.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.