4

I am trying to paste from the windows system clipboard into a terminal text editor like vim (or its clipboard and xterm-clipboard allowing variants like vim-gtx), nano or emacs to no avail.

I am mainly attempting it with vim-gtx since vim is my favorite editor -> but no matter what method I try, whether it is:

  • Using :set paste and pasting with Ctrl-v,Shift-ctrl-v (this is the only method which pastes any clipboard content at all)
  • Pasting with "*p or "+p (doesn't paste)
  • Copying input to clip.exe (have tried xclip but this utility doesn't seem to work on WSL), and then pasting into vim.

AS mentioned above, pasting from the clipboard only seems to work when pressing Ctrl-v in insert mode (Shift-Ctrl-v inserts a '^', and "*p and "+p inserts an 'i' character or '^?'), and the pasted output always pastes onto a single line.

For example, a section of the default .bashrc file copied from VSCode:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Will paste as the following into a terminal text editor:

# enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if ! shopt -oq posix; then   if [ -f /usr/share/bash-completion/bash_completion ]; then     . /usr/share/bash-completion/bash_completion   elif [ -f /etc/bash_completion ]; then     . /etc/bash_completion   fi fi

If making EOL characters visible, then a $ appears just after the final character. This problem occurs no matter which editor is used, from where the text is copied from, and no matter which pasting system is used (if the pasting is successful at all).

To sum up:

  • Ctrl-v in vim is the only way to paste anything, but pasting occurs on a single line only

  • "*p / "+p in vim does not paste as expected (but works in vim via git-for-windows, see note below)

  • I'm unsure of how to paste from system clipboard into nano and emacs (ordinary pasting and piping output to windows clip and then pasting doesn't paste anything in these two programs - I can only paste after yanking/copying internally).
  • So, it could be a problem (with all) varieties of vim on Ubuntu for Windows.

Thanks

Important Note: -When pasting with "*p on vim via git-for-windows (instead of Ubuntu bash), it pastes correctly (with new lines). But Vim (vim-gtx, or ppa version) via Ubuntu is unable to paste properly with "*p - it's looking to perhaps be a problem with vim being ported to

  • 3
    It could have something to do with how Windows linebreaks are different from UNIX linebreaks. What you could try is downloading Sublime Text Editor, pasting the text into there, then going to View-->Line Endings-->UNIX and pasting the text from Sublime into vim. – TheWanderer Jul 5 '17 at 12:23
  • Thanks for the input! I've tried this and it doesn't make a difference. I've made an edit to my post. I realised that pasting works with "*p via vim on git-for-windows, but not on Ubuntu for Windows. It's perhaps looking to be a problem with (all?) varieties of vim on Ubuntu for Windows? Do you perchance know of a way to paste from system clipboard on nano/emacs? (I thought I was doing this before but perhaps I'm doing it wrong) - if I can rule out one of these editors and its pasting options, then vim can be ruled out as being the problem! – Samuel G Jul 5 '17 at 13:11
  • Right-clicking is how you paste into a CMD window. I just tried it now in nano and it worked for a URL. It also worked when I copied your example text and pasted it. Line breaks were kept. – TheWanderer Jul 5 '17 at 13:15
  • I've just tried it in nano - and it works. Thank you. The problem then, seems to be vim – Samuel G Jul 5 '17 at 13:19
  • I guess so. If nano works for you though, that's definitely good. – TheWanderer Jul 5 '17 at 13:20
0

Try this chain: Control + R then Shift + =

0

This question was written in June 2017 and many have requested WSL copy and paste support. In response Microsoft released an update in April 2018: Copy and Paste arrives for Linux/WSL Consoles:

As of Windows 10 Insider build #17643, you can copy/paste text from/to Linux/WSL Consoles!!!

We know that this is a feature MANY of you have been waiting for - our sincerest thanks for your patience & continued support while we untangled the Console's internals, allowing us to implement this feature.

To ensure that we don't break any existing behaviors, you'll need to enable the "Use Ctrl+Shift+C/V as Copy/Paste" option in the Console "Options" properties page.

Note: You will need the Windows September 2018 update to use the new feature.

0

Define Bash variable $EDITOR to any of choice i.e.

      export $EDITOR=/usr/bin/nano 

Then use Ctrl-x Ctrl-e that launch nano. Then you could paste multiline selection after save you return to shell with command filled from edit. # update just after a while, want to add that the trick with nano is based on new capability of WSL gained as mentioned with one 2018 update.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.