Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: copy entire contents from vi editor on to clipboard

  1. #1
    Join Date
    Aug 2012
    Beans
    623

    copy entire contents from vi editor on to clipboard

    Hello,
    I am working by ssh'ing onto a remote server using putty and so vi is the only software I have at my disposal.

    I would like to copy the entire contents of a text file from this server on to my local computer. Assuming I cannot scp the file, and the only way I can do this is by copying and pasting, how can I copy all the contents from this file on to the clipboard, so I can paste on to my local system.

    I have tried the following, but wasn't successful.
    Code:
    gg"+yG
    Code:
    :%w !pbcopy

  2. #2
    Join Date
    Mar 2009
    Beans
    1,982

    Re: copy entire contents from vi editor on to clipboard

    ssh and scp are the same server, same protocol. If you can edit it in vi then you can scp it.

    Failing that, there are command line tools like pastebin which might be helpful, designed to copy entire files.

  3. #3
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,546
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: copy entire contents from vi editor on to clipboard

    I usually just highlight all the text, right-click to choose Copy, then Paste it into the destination. For longer files, you'll need to repeat this until you've captured the whole file.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  4. #4
    Join Date
    Jul 2005
    Location
    I think I'm here! Maybe?
    Beans
    Hidden!
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: copy entire contents from vi editor on to clipboard

    Quote Originally Posted by SeijiSensei View Post
    I usually just highlight all the text, right-click to choose Copy, then Paste it into the destination. For longer files, you'll need to repeat this until you've captured the whole file.
    In vi (or nano)?

    Surely you can't do that in the cli editors, or if you can, I am not aware of it, nor how it can be done.

  5. #5

    Re: copy entire contents from vi editor on to clipboard

    Code:
    ssh user@host cat  /etc/rsyslog.conf  > ./woof.txt
    is what I do, where "ssh user@host" are dozens of hosts.
    and I heavily use aliases for rapid access to remote hosts, so
    Code:
    <host_alias> cat /some/file > ./here.local
    shoots me in and out and done.
    Windows assumes the user is an idiot.
    Linux demands proof.

  6. #6
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,546
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: copy entire contents from vi editor on to clipboard

    Quote Originally Posted by ajgreeny View Post
    In vi (or nano)?

    Surely you can't do that in the cli editors, or if you can, I am not aware of it, nor how it can be done.
    My method uses the native copy/paste functions of the Terminal client. While I use Konsole (KDE), I'd be surprised if you can't highlight and copy text from other graphical terminal clients as well.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  7. #7
    Join Date
    Jul 2005
    Location
    I think I'm here! Maybe?
    Beans
    Hidden!
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: copy entire contents from vi editor on to clipboard

    Quote Originally Posted by SeijiSensei View Post
    My method uses the native copy/paste functions of the Terminal client. While I use Konsole (KDE), I'd be surprised if you can't highlight and copy text from other graphical terminal clients as well.
    You may be correct, but if so I can still not figure out to do it in nano, the cli editor I use, and apart from telling me to use command nano -m to enable mouse use, man nano does not help me.

  8. #8
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,546
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: copy entire contents from vi editor on to clipboard

    No, you cannot do it from within nano or any other text editor. They have no way to communicate to X and the desktop environment. You need to use the standard Copy/Paste functions built into the desktop environment, in particular those found in the GUI Terminal app itself. Unless you're running in pure text-mode (like at the recovery console), you're using nano within a Terminal window, right?

    Try painting the text with your mouse, then right-click on the highlighted text. Can you choose Copy? How about if you highlight the text and choose Edit from the Terminal window menu?
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  9. #9
    Join Date
    Jul 2005
    Location
    I think I'm here! Maybe?
    Beans
    Hidden!
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: copy entire contents from vi editor on to clipboard

    I tried painting the text in nano with the mouse and it did not highlight text or do anything.

    I then had a bit of a brainstorm and read man nano in more detail; I had set an alias for nano using nano -B -S -m -$ without realising that the mouse enablement when using the -m option was not what I thought it should be; it simply allows you to place the cursor by clicking in the text, but it removes the ability to highlight text and use the copy/paste from right click.

    So, my problem is solved, and I have to accept that it was my own fault; a result of me trying to be clever, but messing up what already was possible if I did not use the -m option for nano.

  10. #10
    Join Date
    Mar 2009
    Beans
    1,982

    Re: copy entire contents from vi editor on to clipboard

    I haven't actually tried any of this but I can think of a couple ways you might do this from inside vim. The caveat is that you scp the saved version of the current file back to your workstation. You would need ssh server running on your workstation.

    So for example you could do something like:
    Code:
    who am i | sed 's/^\(\S*\)..*(\(.*\))/\1\@\2/'
    You'll get you@your-ip-address, but only if you're logged in remotely. Likewise in vim tips here http://vim.wikia.com/wiki/Get_the_na...e_current_file say that you can get the current filename being edited fairly easily.

    It seems to me that with a bit of experimentation you could:
    Code:
    :!scp <something-from-the-vim-tips-website> `who am i | sed 's/^\(\S*\)..*(\(.*\))/\1\@\2/'`
    The only serious loophole here is that this assumes you have the same login name on both boxes. And that your client is reachable by ssh at the reciprocating address (so not if you're behing a nat firewall for example)

    The key being of course that all this is much harder than opening a second terminal from your client box, and
    Code:
    scp you@remote_host:/path/to/file ~/Downloads/file
    Just saying, if you can ssh over and edit the file then you can absolutely positively scp it from the same box. ssh and scp are the same protocol.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •