How do I copy lines of code from vim into a google doc? [duplicate] - vim

This question already has answers here:
How to copy to clipboard in Vim?
(40 answers)
Closed 18 days ago.
I understand how to copy lines inside vim to use in vim, but whenever I try pasting the code anywhere else outside my terminal it pastes a previous copy that was not done in the terminal.
I have been searching past questions on here about this, but none of them seemed to work or be what I was looking for.

You try with the standart Ctrl + C. In my case, when i copy from a terminal (not vim) i do it with Ctrl + Shift + C.

On MacOS while in terminal if you go to view then uncheck "Allow Mouse Reporting" you will be able to copy/paste any lines to your systems clipboard.
Make sure to recheck this after your done or else the terminal acts weird when going into vim.

Related

How to select all text in vim normal mode?

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
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.
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>
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++.

How to copy all the text from vim editor using vim command line?

I want to select all the text from the vim editor, I tried the command :%y+ but getting error E850: Invalid register name. I get this command from this link. Please help me how to copy all the text from file which is open in vim. They are using yank, what is meaning of it..
I had a similar problem. Don't know why you got so many down votes.
The problem is that you haven't installed vim-gnome which takes about 24 MB and adds a feature to the inbuilt vim.
sudo apt-get install vim-gnome
then your command will work. :%y+ This command will copy all the text in system's clipboard.
TLDR: If you want to copy text in Vim to the system clipboard type ggVG"*y. Explanation below...
Vim runs in the terminal and, depending upon how you are using it and which type of Vim you are running, it's not really designed for you to select text with a mouse and copy and paste in the traditional way.
If you want to select all of the text using Vim then use ggVGy (note the uppercase VG in the middle). This command moves the cursor to the top of the file, enters visual mode, moves to the bottom of the file (thus, selecting all of the text) and then yanks (copies) it. You can then use p to put (paste) this code but only inside of Vim.
If you want to copy to the clipboard to use somewhere outside of Vim then try this:
First, select everything using the commands outlined above but without the final y: (ggVG). Then press "*y. This should now copy it to your operating system's clipboard and you can just paste (Ctrl/Cmd+v) anywhere you want outside of Vim. This can vary depending on what settings you have for Vim but it should work.
A brief explanation of the commands used. gg goes to the top of the file. V enters visual mode by lines. G goes to the end of the file. y yanks (copies) the text but not to the clipboard. p puts (pastes) the text.
The more advanced (i.e. cool) stuff:
" allows you to access registers. For example "a provides access to register a.
The * is the system clipboard so "* provides access to the system keyboard. Therefore, "*y yanks into the system clipboard.
While there's a great explanation of how to exploit the system clipboard in vim, it sounds like you're just having trouble getting your vim to access the clipboard in the first place. Try installing vim-gnome, it gives you the packages you need to get to the system clipboard.
For some reason, "* didn't work for me, but the exact same command with the "+ register did.
To select the whole file you can jump to the beginning, start visual mode, jump to the end:
ggVG
This question is a few years old now, but I had this same problem on Linux Mint 18. I found using xclip worked for me. You can map the command vmap <F7> :!xclip -sel c<CR><CR> in your .vimrc to have your current selection in visual mode copied to the system clipboard.
Here is a thread containing the above (and other) solutions.
You can use
Vggy/vggy or,
VGy/VGy
To visually select any number of text and then copy it, in your case it is gg / G as you want all text on the file,
gg is to copy while your cursor is at bottom of the file, gg for go to top
G is to copy while your cursor is at top of the file
Or even you can always use
Vk(as number of time)y to copy the selected lines of text.

Copy / Paste Vim system clipboard [duplicate]

This question already has answers here:
How to make vim paste from (and copy to) system's clipboard?
(36 answers)
Closed 8 years ago.
What is the quickest way to copy paste between VIM on command mode and system clipboard without touching the mouse on Linux ?
On Windows the special register "* contains the clipboard, so you can just press CTRL-r* in insert mode to insert its contents. See here.
The short answer is: It depends.
The correct answer, you may find on the respective VIM wiki:
http://vim.wikia.com/wiki/Accessing_the_system_clipboard

Why is VIM's copy and paste broken and how to get it right? [duplicate]

This question already has answers here:
How to make vim paste from (and copy to) system's clipboard?
(36 answers)
Closed 8 years ago.
One thing I haven't figured out is how to get vim's copy and paste to work correctly.
Can someone explain why it doesn't out of the box and how to get it to work that preserves the spacing etc?
e.g. if I copy and paste a block of code from a browser, it should paste into vim with the spacing in tact.
Turn on paste mode with :set paste to stop vim applying any indentation to the pasted text.
Adding to desbo's correct answer, you can quickly toggle the option with
:set paste!
Now if you have the idea "hey, a mapping is even quicker"; that won't work, as mappings are disabled in paste mode. But Vim provides a workaround through a special option:
:set pastetoggle=<F11>
Lastly, if you use the GUI-version gvim, you don't need to care about all of this, as it is able to differentiate typing from pasting by itself.

GVIM : Possible to begin editing the file without having to press "i"? [duplicate]

This question already has answers here:
Is there a way to change vim's default mode
(5 answers)
Closed 9 years ago.
I am trying to move from GEDIT to GVIM but I noticed that when I open a file I am not free to edit it.
unless I press i to go in (INSERT) mode.
Is there a way to bypass this? So the file is instantly editable?
You can do this by editing your .vimrc file. It looks like set im! is the command you're looking for to set input mode as the default, but you'll also need to explicitly map escape to change to command mode.
A better question is why you would want to do this, though. Unless you're opening a brand new file, once you know vim, you'll probably spend very little time in insert mode, as you should be using more advanced command-mode commands (append, correct, etc) to edit and update your code at the appropriate places. If you're just going to use vim the same way you use gedit, don't bother - gedit is better than vim at being gedit.
EDIT: After reading the comments on your question, it sounds like you really, really shouldn't be using vim. It's not something you want to stumble into by default, certainly not if what you want is a basic editor with customizable display.

Resources