0

I am using ZOC, used Windows CMD as well, the same thing, when I highlight the text using VIM and run command like "+y or "*y, and then, try to paste in my Windows local editor, the output is blank, which makes me thinking, that the highlighted text has not being copied/delivered to the system clipboard through the SSH connection...

Similarly, the "+p is not pasting the clipboard contents from system clipboard..

System Info:

pi@readonly:~/new$ vi --version | grep IMproved
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 30 2017 18:21:38)
pi@readonly:~/new$ vim --version | grep clipboard
+clipboard       +job             +path_extra      +user_commands
+eval            +mouse_dec       +statusline      +xterm_clipboard
pi@readonly:~/new$    

When I open any file in VIM, and try to check for the register +, I am getting this:

:reg +
--- Registers ---
Press ENTER or type command to continue   

Also, when I run :echo has('clipboard'), I am getting 1

@PatrickBacon, I have yanked the highlighted text by clicking on v, scrolling through the text and using "+y. Here are the registers showing:

:reg
--- Registers ---
""       int c;^J    for (i = 0; i < sizeof(s) - 1 && (c = getchar()) != EOF;) {^J       s[i++] = c;^J       if (c == '\n
"0       int c;^J    for (i = 0; i < sizeof(s) - 1 && (c = getchar()) != EOF;) {^J       s[i++] = c;^J       if (c == '\n
"1   ^J
"2   ^J
"3   p^J
"4   ^J
"5   ^J
"6   p^J
"7   p^J
"8       char s[64];^J    size_t i;^J
"9   int atoi(const char *s) {^J    int n = 0;^J    size_t i = 0;^J^J    while (s[i] == '0')^J        i++;^J    if (s[i]
"r         while (s[i] >= '0' && s[i] <= '9')^J            n = 10 * n + (s[i++] - '0');^J
"u       size_t i = 0;^J^J    while (s[i] == '0')^J        i++;^J    if (s[i] >= '1' && s[i] <= '9') {^J        n = s[i++
"z   t main() {^J    char s[64];^J    size_t i;^J    int c;^J
"-   i
"%   t.c
Press ENTER or type command to continue 

Hence, it looks like the yanking is working within vim..

Questions:

1) What else I should check to verify, that all the requirements for "Copying highlighted in VIM text into the remote system clipboard" have been met?

2) Do the registers that exist within VIM, are the real files in some directories in my Linux, buffered?

3) How does the remote system clipboard looks like to the Linux system, to which I am connecting via SSH? In other words, does the remote system clipboard is simply the STDOUT file or part of it, on the Linux?

readonly
  • 89
  • 7
  • *2) Do the registers that exist within VIM, are the real files* Nop, they are memory buffers. – phd Jan 17 '19 at 20:48
  • 1
    If you are using linux you have to use vim-gtk to be able to copy to clipboard, it's all explained here (https://stackoverflow.com/questions/3961859/how-to-copy-to-clipboard-in-vim) – Santi Jan 17 '19 at 20:48
  • *3) How does the remote system clipboard looks like to the Linux system, to which I am connecting via SSH?* There is no such thing as a `system clipboard` in Unix/Linux. There are clipboards and copy buffers in X Windows. – phd Jan 17 '19 at 20:49
  • @phd What do you mean by 'memory buffers'? In other words, do you mean, the VIM itself consume some RAM on the runtime and the files are stored within it, or expanding...? – readonly Jan 17 '19 at 20:49
  • Yep, exactly so. – phd Jan 17 '19 at 20:49
  • @Santi Already installed both `vim-gtk` and `vim-gnome` - no go... – readonly Jan 17 '19 at 20:50
  • Hi, it looks like your yank is not yanking anything. Can you navigate to any word and yank it (e.g. `"*yw`). Next, check your registers (e.g. :reg). – Patrick Bacon Jan 18 '19 at 00:49
  • @PatrickBacon, I have added the output of :reg, after yanking some text in the main body... – readonly Jan 18 '19 at 07:41

1 Answers1

0

In general, you can't copy text from a remote system program to the current system natively over SSH. The exception is when you run an X11 server on your local machine and the remote system runs an X11-compatible client, and you have X forwarding enabled for the SSH connection. Since you're using Windows, I doubt that you're running an X11 server on your local system.

Clipboards are a feature of whatever window system you're using, and Windows and X11 (the typical Linux window system) don't share a compatible interface. The X11 clipboards (there are multiple) are stored in memory in the program until the X server speaks to the program with the clipboard data and asks for the data in a particular clipboard. This data isn't just standard output; it's a dedicated block of memory and a particular protocol.

If you want to be able to copy blocks of text from a remote terminal, the easiest way is to use something like tmux on your local system, and then connect to the remote system through tmux. You can configure tmux to copy and paste data from the terminal into your clipboard using shortcut keys. This will result in a configuration that works for all terminal programs and connections run within tmux, not just Vim.

For example, you could use a key binding like the following (bound to y) to automatically copy and paste to the Windows clipboard:

bind-key -T copy-mode-vi y send -X copy-pipe 'clip'
bk2204
  • 64,793
  • 6
  • 84
  • 100
  • I have installed tmux and set it in the .tmux.conf, however, still, when copying using VIM, specifically, using v and make a selection, then press y, returning to my OS, nothing can be pasted to notepad...Any thoughts? – readonly Jan 26 '19 at 17:58
  • If you use tmux for copying and pasting, you cannot use the Vim keybindings; instead, you need to use tmux to copy and paste. There isn't any way to honor the Vim keybindings over SSH unless you're using X forwarding. – bk2204 Jan 26 '19 at 19:31
  • So, can I still use vim, as editor, but, copy the line, within it, using key combination, according to tmux setup? If yes, which combination I should use according to "bind-key -T copy-mode-vi y send -X copy-pipe 'clip'"? – readonly Jan 26 '19 at 19:38
  • According to that example, you'd hit the tmux key (default Ctrl-B), then `[`, to enter copy mode, then select the area to copy, and hit `y` to copy. If you're using emacs mode for tmux instead of vi mode, change the binding to use `copy-mode` instead of `copy-mode-vi`. – bk2204 Jan 27 '19 at 01:41
  • Sorry, I am not clear about it, first, I connect to remote machine, type in `tmux` and enter, `vim t.c`, then press `ctrl+b`, then `[`, I am getting `[0] 0:[tmux]* "readonly" 08:46 27-Jan-19` line on the bottom and on the right hand side: `[0/36]'. But now, which combination I can use to select the actual text and copy into the remote, "Windows" clipboard? – readonly Jan 27 '19 at 08:48
  • Also, when I press `ctrl+b`, the vim screen is frozen, hence, I am not able to scroll down, in case the file is big, that is my actual goal, to be able to copy the selected lines from, which could be bigger than the actual screen. – readonly Jan 27 '19 at 10:07
  • You highlight text by selecting the place to start with the arrow keys, pressing space, and then navigating to the place where you want to finish the selection and pressing `y` to copy. However, tmux, unfortunately, is only able to copy what's on the screen, not what goes outside of it. – bk2204 Jan 27 '19 at 17:06