0

I have set VIM as the default editor in the Terminal.

I changed the ~/.bashrc:

export VISUAL=vim
export EDITOR="$VISUAL"

You can also set the default editor only for git:

git config --global core.editor "vim"

So far so good.

When I open VIM on its own, it opens in the Terminal frame. When I make a git commit, it pops up inside the same Terminal window I am in, which is good.

Now to the problem. I am a beginner at VIM and I follow what is the command for "Select All" in vim and VsVim?. I cannot right-click and copy after selecting all (ggVG), it is the normal Terminal menu that pops up, and VIM likely does not have any such menu anyway.

enter image description here

With VIM shortcuts, it does not work either.

  • Ctrl+Shift+C does not work.
  • When I press y to "yank" (which is also not a clear copy command from a beginner's perspective...) the text loses the selection again, but the clipboard is still unchanged.
  • Yet, when I mark text in Visual mode "V" or in Insertion mode "I" with the mouse, then of course just the text that I can see on the screen without any scrolling, I can copy (using the right-click menu of the terminal again):

enter image description here

  • If I mark all with the command from the link above and then shrink this line by line with the Shift and the Page Up key until I have only a one-pager, I still do not get a working Copy symbol in any step - also not when I reach the one-pager. Copying is only possible with text that can be seen in the window.

  • I can also press v and just select something that can be seen on the screen and press y to copy, works fine. But I cannot go over the screen border and do the same. As soon as scrolling is needed, or as soon I go to the end of the file, I cannot use y anymore. I have shown this to another user of VIM and he was also surprised, proving that I have not just misunderstood something here.

How can I ungrey this terminal "Copy" button in the right-click menu when all of the text is selected? Or which VIM shortcut can still copy when the "Copy" symbol of the right-click menu is greyed out?

PS:

Since I did not want to risk the file content that I had in a Docker container only with some hour of work in it, I decided to copy and paste, step by step, a larger code file before trying even "y" for yank or more shortcuts. With research and this question here I lost half an hour only to try copying my work. Is this murphy's law in action or just a beginner's stupidity so that only I have this problem?

5
  • 1
    it may be that y copies to the unnamed and 0 registers as usual, whereas you need something like "*y or "+y to yank to clipboard registers.
    – D. Ben Knoble
    Jan 31 at 14:54
  • @D.BenKnoble thanks but no, that does not work either, tested both double quote commands. After the y, the selection is lost, but nothing is in the clipboard. It is also happening when I use VIM just in a normal terminal as the forced editor for a git commit. Feb 1 at 17:08
  • Hm. You said you were in a container—probably it does not share the hosts clipboard. I use the star register all the time to yank to and put from the clipboard, but you need a version of vim compiled with clipboard support. PS an easier command is :%y[ank] [register]
    – D. Ben Knoble
    Feb 1 at 18:23
  • Are you sure this popup menu is from vim? Looks like terminal menu for me.
    – Maxim Kim
    Feb 1 at 18:25
  • @D.BenKnoble the same problem is also in a normal terminal when I write a git commit message. It does not depend on the container. Yes you are right, I get the same menu in the terminal without having VIM opened with Copy also being greyed out then! That explains it, I have VIM as the default editor in terminal (export VISUAL=vim export and EDITOR="$VISUAL"), and the right-click menu is still the terminal right-click. Even if I open VIM directly it is opened in the terminal. And that might block the copying of more than the terminal window "that can be seen". Feb 1 at 19:30

2 Answers 2

1

How can I ungrey this terminal "Copy" button in the right-click menu when all of the text is selected? Or which VIM shortcut can still copy when the "Copy" symbol of the right-click menu is greyed out?

You can't ungrey terminal "Copy" menu for vim's visual selection. It only works for terminal selection.

To use vim copy to system clipboard/paste from system clipboard you have to have vim compiled with +clipboard feature (usually comes with vim-gui or vim-gtk packages). And your linux should have X server being run, for wayland vim doesn't have anything built-in as of now.

And then use "+y to copy vim's to system clipboard.

See another answer on the matter: How can I copy text to the system clipboard from Vim?

1
0

Workaround for anyone who is fine with using the terminal tools to copy from vim, which is helpful if you are not allowed or do not want to install the clipboard and setup the xserver only to copy from terminal to the system:

you can install the "Alacritty" terminal which embeds vim text inside the terminal text so that you can copy as if you were in the terminal, even when you are in vim.

I found out about this when I was on an old legacy server where I was not allowed to install any plugins. In Alacritty, I used ssh to get there, and I could scroll-mark with the mouse a longer text and then copy it.

See How to copy multi-page text from the terminal into the clipboard?.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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