I use the following command to copy the content of a text file (located in remote server) opened with VIM (Linux OS):
gg v shift+g
The text is selected and greyd out as seen in the screenshot
But I don't know how to copy it in clipboard in order to paste it later in another vim file (in my host machine)
If I understand you right, you are going in the wrong way.
I guess you opened the remote file via ssh. You cannot copy to your local clipboard directly over a remote ssh.
I would suggest that, you open the file from your local vim, via :e scp://server//path/file or open it in a split window in your local vim. Then you are free to yank/copy content from your remote file to your local vim file(s).
Related
I was working samba on raspberry pi using putty to connect. I configured the smb.conf file using nano as my text editor. Try to use vi editor but it doesn't allow me to put in space or create a new line.
After I restart samba. It creates smb.conf.save file. When I try to nano smb.conf(the original file), it shows nothing like a blank page(see below image). It also crushes since I cannot go back to the command line. I have to close and open it again.
When I try to use vi editor to view smb.conf. I am able to view the text.
Does anyone know what is the problem? How to fix it? Thank you.
Basically vim saves your buffer (unsaved edit) in a temporary file with .save extension so you can use this as backup in case something happens like unexpected system reboot
VIM is a bit different from other text editors. It has multiple modes insert mode (where you can edit text) and command mode (where you can use alphabet keys to do commands like go up using k and delete using dd etc. Once you open vim you are on command mode so you cannot edit your text until pressing I to jump to insert mode.
Check https://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm
My answer for your issue will be either to take a quick tutorial about vim then edit using vim or use nano to open .save file edit your file then when save delete the .save extension
I would like to copy the following function and paste it into a shell outside vim:
Once I have selected the text I have tried doing "+y and it yanks the text, and allows me to copy-paste that into another vim editor, but if I try copying it into another terminal shell, it doesn't do anything. Now how I have to do it is use my mouse, remove the line numbers, and highlight those lines 37-42. What would be the proper way to yank/copy the text so I can paste it into other programs. Note that this is on a remote ubuntu server.
Note that outside of vim, I would have to use Cmd p to paste in the text (my local machine is a mac).
I'm trying to select a block of text from the Unix VIM editor in console (I'm using Putty) and paste it into notepad. I've already read all the threads here and nothing is working.
What I've done so far:
sudo apt-get install vim-gtk (+clipboard +xterm_clipboard activated)
vimrc file: maped "+y to Ctrl-c (for convienience)
V to select block of text in visual mode (for example 132 lines)
Ctrl-c to copy text (the mapping above works, so it says "132 lines yanked")
PROBLEM:
When I go to Windows Notepad try to paste the text, nothing happens. Why and how to fix?
Thanks
Kind regards
What you are doing should get your yanked lines into the X11 copy buffer on the remote machine, but to get as far as Notepad on your local machine you need a couple more pieces.
An X server that will treat the X11 and Windows clipboards as
unified. I believe Xming will do this, probably others as well.
X11 Forwarding enabled in putty (and allowed by the ssh server).
All other things being equal, it's a lot easier to just copy lines in Putty and paste in the traditional way. If this breaks formatting you need to preserve, you might consider working on the remote file and copying it to your workstation using scp or some other means.
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++.
I have two files A and B. A is on my local machine and B is on a remote machine. I want to certain text from A to certain locations in B. I'm using vim. What is the best way to do this?
If both files were local, I would just do
vim A
:tabedit B
then I'd be able to easily switch between the two. Is there anything similar for remote files?
What you are looking for is included with netrw. Take a look at :h netrw and :h netrw-read. So you could just type the following to edit thats on the remote server.
tabedit scp://[user#]machine[[:#]port]/path
(A copy of the file is pulled to the local machine and then when you save it is uploaded to the remote)