4

Is there "keyboard-only" way to select an entire vim document in a way that is equivalent to a left-click and drag with a mouse in normal mode? Please do not confuse this with selecting all text in visual mode (ggVG). I want to be able to follow this up with a right-click paste into notepad++ (ggVG/ggVGy followed by a right-click paste in notepad++ does not copy the document). Thanks

mkrieger1
  • 10,793
  • 4
  • 39
  • 47
gobot6
  • 123
  • 1
  • 1
  • 6
  • Interesting, I wonder if thats possible – Bishal Feb 23 '17 at 23:58
  • While this may be on-topic here, you may want to check http://vi.stackexchange.com – iled Feb 24 '17 at 00:05
  • I was going to mark this as a duplicate question (http://stackoverflow.com/questions/1620018/copy-all-the-lines-to-clipboard), but I'm using MacVim on OSX and `gg"+yG` doesn't copy to the system clipboard for me. – Matt Feb 24 '17 at 00:10
  • Possible duplicate of [Copy all the lines to clipboard](http://stackoverflow.com/questions/1620018/copy-all-the-lines-to-clipboard) – mkrieger1 Feb 24 '17 at 00:14

3 Answers3

5

Again, the "ggVG" commands are not working, nor are the "+y" commands (which I should have mentioned in my original post). Perhaps it is worth noting that I am working on a Windows local machine (where I have notepad++ open) and am generating the vim file on a linux virtual machine (slurm cluster). Under these working conditions, if I left-click drag over the vim doc and right-click paste in notepad++, the selected text copies over. However, the process is cumbersome for large files, hence my inquiry. Thanks again.

You should have mentioned that, of course, as it is not a meaningless detail at all.

Manual selection in a terminal can only select the text currently displayed in the viewport, which is obviously cumbersome for larger files. The only practical way to copy on the remote machine and paste on the local machine (and vice-versa) is to enable X-forwarding and build Vim on the remote machine against X libraries. This will give you what you want: a shared clipboard.

You won't be able to reach your goal in a practical way if you can't or don't want to install the necessary stuff on the remote machine.

As a lightweight alternative, you could simply scp the remote file to your local machine.

romainl
  • 158,436
  • 18
  • 236
  • 264
  • Thanks for the information. I'm not authorized to perform the necessary installations on the remote machine so it will have to be a PuTTY scp. – gobot6 Feb 24 '17 at 21:09
3

Just use (esc:%y+. This will copy the entire document to your clipboard. Then you can go to notepad++, or whatever else you want to use, and paste it with a right click.

Explanation:
%: Tells vim the next command will be applied to all lines.
y: to all 'yank' lines
+: Copies all lines to clipboard, You can also use Ctrl + C instead. Note: + is sometimes bound as *. And sometimes both are equivalent.

Or you can also use the slightly longer way: ggVG+.

If you really want to be fancy you can remap Ctrl + A to ggVG or %y by adding this line to your .vimrc:

map <C-a> <esc>ggVG<CR>

zoecarver
  • 3,888
  • 2
  • 18
  • 39
  • Again, the "ggVG" commands are not working, nor are the "+y" commands (which I should have mentioned in my original post). Perhaps it is worth noting that I am working on a Windows local machine (where I have notepad++ open) and am generating the vim file on a linux virtual machine (slurm cluster). Under these working conditions, if I left-click drag over the vim doc and right-click paste in notepad++, the selected text copies over. However, the process is cumbersome for large files, hence my inquiry. Thanks again. – gobot6 Feb 24 '17 at 01:11
  • I could PuTTY the vim files over to my local machine but I'm hoping there is an easier way – gobot6 Feb 24 '17 at 01:17
  • If copy and past works, you can try `gg` then shift + `v` and finally shift + `g`. Then just copy and past. If this works tell me and I will update my answer. Hope this helps! – zoecarver Feb 24 '17 at 01:18
0

Try to use Xshell remote login software. in there is a option called "To Text Editor".

Just open the file using "vi filename.c" it will displayed on the screen after that just made a left click on the work area and choose "To Text Editor--->all" . then these all text moved to a notepad file then u can simply copy and paste in notepad++.