0
<tspan x="0 0.54717 0.75472 1.32077 1.81134 2.35851 2.58493 3.13213.39625 3.96229 4.50947 ">Lincoln 30%</tspan>  

I have to yank the text between the tspan tags 32 times in a XML document.
This is what I did: vsplit and enew to create a seperate window. Key combination:" vit and yy" to select and copy text between tags. Go to new window and paste and return to old window. This 32 times.

It works but my question: do you know a more efficient way of doing this?

  • Reply to my own question: using buffers of course. – user3467407 Jun 13 '17 at 8:38
1
  1. :vnew is more effcient than :vsplit followed by :enew.

  2. yit is more efficient than vit followed by y.

  3. Okay I'm being facetious. Sorry. To actually answer your question, macros (:help complex-repeats) can playback commands that move the cursor to other windows, so you can use them for this sort of task. You might need to tweak this to work with the contents of your file, but the basic steps are:

    1. /tspan<cr>: Search for the first tag.
    2. f>l: Jump into the element contents.
    3. qq: Start recording into the q register.
    4. yit : Yank the text.
    5. ctrl-w w: Move cursor to your other window.
    6. o<cr>p: Paste the yanked text into a new line.
    7. ctrl-w p: Move cursor back into the first window.
    8. n: Jump to start of next tag.
    9. q: Stop recording and save the macro.


    You can then play the macro back 31 times with the command: 31@q.

  4. You could probably also do it with a :global command.

  • Thank you, that was the answer I was looking for. I answered my own question saying that buffers would be the solution. I meant registers. – user3467407 Jun 13 '17 at 9:56

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.