vimrepeatvim-pluginsurround

Using vim-surround with argument to a function


I'm new to vim-surround. I would like to achieve the folowing.

I have an html file with many images as this (* is the cursor position):

<img src="ima*ges/pages/img1.jpg" alt="">

And I would like to change it with this:

<img src="{{ media_url('images/pages/img1.jpg') }}" alt="">

I tried ys"f but it doesn't work as expected. I would like to change all jpg images with such pattern, I'm aware of vim-repeat I will dig into it once I could change the first correctly.

If you know a way to achieve this to all jpg occurrences I would be really thankful.

Thank you very much.


Solution

  • You will need to record a macro and then execute on all images.

    In normal mode position your cursor at first " start recording a macro with qq then:

    cs"'va'hSbimedia_urlbvf)S{gvS}gvS"q

    Now you have recorded a macro in q register. Execute it whit @q.

    Position your self at next image(") and the @q. You can combine it with find (/"ima) then combine n and @q.

    If you position yourself with find on next word while recording macro you can prefix macro with number ... 10@q execute it on 10 images....