Copy and paste from external source

后端 未结 5 529
半阙折子戏
半阙折子戏 2021-01-02 05:21

I use vim (Actually gvim on windows) as my main text editor. In my work flow I have to copy sentences to/from various external sources, therefore I use clipboard=unnamed to

相关标签:
5条回答
  • 2021-01-02 06:00

    Try this:

    :vmap p "_xP
    
    • vmap means to make a mapping that only applies in visual mode.
    • p is the key to create the mapping for.
    • "_ is the black hole register. This is used in any situation where you want to delete text without affecting any registers.
    • xP means delete the selected text, then paste before the resulting cursor position.
    0 讨论(0)
  • 2021-01-02 06:04

    I don't know how to do that on Windows. With KDE, the clipboard has a history that you can select from, so you could do the paste, select the previous selection from the clipboard, and paste in the new location.

    That said, it sounds like it might make more sense for you to have it in only one location, then write a script to take that input and create the output you need. Can you elaborate more on what it is you are trying to accomplish?

    0 讨论(0)
  • 2021-01-02 06:19

    You could set up a mapping to ease your pain:

    :vmap <F5> "zxP
    

    This will delete the visually selected text, but put it in a different register, so the clipboard isn't affected. Change <F5> to whatever is easiest for you.

    0 讨论(0)
  • 2021-01-02 06:21

    Check the value of the 'guioptions' options. Make sure the 'a' flag is not set. Also, check that the 'clipboard' option and verify that neither the 'unnamed' or 'autoselect' flags are set.

    :set go-=a
    :set clipboard-=unnamed
    
    0 讨论(0)
  • 2021-01-02 06:22

    I don't know if I misunderstand you but I tried what you are doing and I have no problem in doing that with the + drop-register.

    My workflow:

    1. copy a sentence in an external application (ie. browser)
    2. visual select a sentence in vim and replaced it with "+p or p (with clipboard=unnamed set)
    3. visually select another sentence and replace it with "+p

    Sadly when pasting the second time you have to explicitly paste from the + register. Therefore I would recommend a mapping for p/P instead of using clipboard=unnamed

    nmap p "+p
    

    Try using

    :registers
    

    to see the contents of the different registers.

    0 讨论(0)
提交回复
热议问题