Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Paste with overwrite in vim

  1. Nov 14, 2013 #1

    DrDu

    User Avatar
    Science Advisor

    I have a recurrent vim problem:
    Often, I want to replace part of a file (call it B) with text from some other file (A).
    So in A I select the lines in question and yank them.

    Now in B i use the visual command to select the region I want to replace.
    I am not happy with it for two reasons:
    1. I would prefer to specify the region explicitly, something like: 1,20v
    however this seems not to be possible with the visual command.
    2. the visual command replaces the text in the yank buffer with the text deleted upon paste.
    If I want to repeat the operation in another file C, I have to yank the text in file A again.

    There must be some more elegant way, however I didn't find it.
     
  2. jcsd
  3. Nov 16, 2013 #2

    Pythagorean

    User Avatar
    Gold Member

    When you open B and C, are you opening them from within A like:

    :eek:pen (B)
    :eek:pen (C)

    ?
     
  4. Nov 18, 2013 #3

    DrDu

    User Avatar
    Science Advisor

    No, usually, I use different windows.
     
  5. Nov 18, 2013 #4

    Pythagorean

    User Avatar
    Gold Member

    Try openng each of the paste files from your yank file. It might depend on your OS (I used slackware last time I was messing with this) but that seemes ti work for me.
     
  6. Nov 19, 2013 #5

    DrDu

    User Avatar
    Science Advisor

    Ok, thank you, I will give this a try. However, I often copy from outside, i.e. form the clipboard, e.g. from a pdf, so this won't work always.
     
  7. Nov 19, 2013 #6

    Pythagorean

    User Avatar
    Gold Member

    If you are able to paste into one vim instance from outside, you might be able to open documents within that vim instance and continue to paste (I always have annoying issues trying to paste from outside, so I don't know). Can always yank it right after you paste it in the first file, too. Often, getting it to actually paste into the first term is where I always have issues (slackware 14.0).
     
  8. Nov 22, 2013 #7

    Pythagorean

    User Avatar
    Gold Member

    I just realized a slightly easier way to do this. Instead of :eek:pen, use :e it allows you to auto-complete with TAB as you dig into directories.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Paste with overwrite in vim
  1. Vim mapping umlaute (Replies: 5)

Loading...