Copying text outside of Vim with set mouse=a enabled

后端 未结 14 817
陌清茗
陌清茗 2020-12-07 06:54

After enabling set mouse=a, text copied inside of Vim will not paste outside of Vim. Does anybody know of a way to fix this?

Here, selecting text with t

相关标签:
14条回答
  • 2020-12-07 07:23

    em... Keep pressing Shift and then click the right mouse button

    0 讨论(0)
  • 2020-12-07 07:24

    Use ", +, y after making a visual selection. You shouldn’t be using the terminal’s copy command anyway, because that copies what the terminal sees instead of the actual content. Here is what this does:

    • ",+ tells Vim to use the register named + for the next delete, yank or put. The register named + is a special register, it is the X11 clipboard register. (On other systems, you would use * instead, I think, see :help clipboard and :help x11-selection)
    • y is the yank command, which tells Vim to put the selection in the register named previously.

    You could map it like this:

    :vmap <C-C> "+y
    

    And then highlight something with the mouse and press Control-C to copy it.

    This feature only works when Vim has been compiled with the +xterm_clipboard option. Run vim --version to find out if it has.

    0 讨论(0)
  • 2020-12-07 07:24

    You can use :set mouse& in the vim command line to enable copy/paste of text selected using the mouse. You can then simply use the middle mouse button or shiftinsert to paste it.

    0 讨论(0)
  • 2020-12-07 07:27

    In ESC mode, when set mouse=a, select the text using mouse. This would enable the visual mode in vim. Then you can press 'y' to yank the selected text and 'p' to paste it wherever you want. This happens only within vim.

    0 讨论(0)
  • 2020-12-07 07:31

    Another OSX-Mac option is to uncheck View->Allow Mouse Reporting (or press ⌘-R to toggle it.) This allows you to toggle between mouse interaction and mouse selecting, which might be useful when selecting and copy/pasting a few bits because you don't have to hold a modifier key to do it.

    Note for Multiline with line numbers:

    I usually have line numbers enabled so this will also copy the line numbers if you select multiple lines. If you want to copy multiple lines without the line numbers disable the numbers with :set nonu and then you can :set nu to re-enable them after you're done copying.

    0 讨论(0)
  • 2020-12-07 07:33

    Press shift while selecting with the mouse. This will make mouse selection behave as if mouse=a was not enabled.

    Note: this trick also applies to "middle button paste": if you want to paste in vim text that was selected outside, press shift while clicking the middle button. Just make sure that insert mode is activated when you do that (you may also want to :set paste to avoid unexpected effects).

    OS X (mac): hold alt/option while selecting (source)

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