Search code examples
vim

How to yank words between dots on multiple lines in VIM?


I try to find the best way to copy (all occurrences) and paste (all the occurrences somewhere else) the second word in between the dots in this example case with vim (without plugins):

1 somename.xyz.something
2 so.someday.zzzz
3 text.example.fese.efsse

The result after I paste it somewhere else:

5 xyz
6 someday
7 example

Solution

  • I would copy the lines in question (e.g. yip or through visual mode) and paste them to the desired location, so you'd get:

    somename.xyz.something
    so.someday.zzzz
    text.example.fese.efsse
    
    somename.xyz.something
    so.someday.zzzz
    text.example.fese.efsse
    

    And then delete the unwanted parts. For example by selecting them in visual mode and running :'<,'>normal 0df.f.D, resulting in:

    somename.xyz.something
    so.someday.zzzz
    text.example.fese.efsse
    
    xyz
    someday
    example