So let's say I have two splits open in byobu, side by side. Furthermore, both splits have different files open in vim. I want to highlight text from one file in one split and copy it to a separate file in the other split. Any ideas?
All the results I found while searching for this talked about using the scrollback feature to copy and paste in byobu, however, that only seems to work inside a single split; not across splits.
Looks like I posted to quickly; seemed to have found the solution. I followed the steps found here:
http://linuxcommand.org/lc3_adv_termmux.php
I followed the steps:
shift-f3 - move to split to be copied from
alt-pgup - enter copy mode
space - start selection
cursor through desired text
enter - end selection
shift-f3 - shift focus to split to copy to
ensure receiving vim is in insert mode
alt-insert - paste selected text
If you are using an X Window Server, an alternative mouse-based solution to using the scrollback mode (which involves remembering a lot of keystrokes) is:
Zoom in on the current pane (Shift-F11), bringing this pane to the foreground.
You can now select the relevant text with your mouse without the vertical split getting in the way.
Unzoom the pane (Shift-F11 again)
Switch to other pane or wherever else you want to paste.
Middle click paste.
If your Vim supports the system clipboard (i.e. if vim --version output shows +clipboard), you can copy into the system clipboard from the first Vim and paste from it into the second one. This releaves us of the need to ensure the receiving Vim is in insert mode and has paste set appropriately.
The trick is to use the "+ register. So when you do the copy, prefix whatever yanking command you want to use with "+; and do likewise prefix the put command you use in the receiving Vim with it.
If you're on an X11 system, you can also use the "* register, which is X's "PRIMARY" selection buffer -- the one where text goes if you just highlight it, and which you can paste by pressing the middle button.
See :help gui-selections. GUI selection support generally requires a Vim other than "vim-tiny"; on Debian and Ubuntu the vim-gtk and vim-gnome packages are good choices.
Related
This is currently how I copy code from an editor to a search field in VS code using vscodevim.
Select text in editor somehow
Right click to open up the contextual menu (since pressing Ctrl+C does not seem to work on Ubuntu, even when in input mode, and 'p' does not work in the search field) and click copy
Press Ctrl+Shift+F to open the search field
Press Ctrl+V
I'm pretty sure this is not how copying from an editor to search field is intended to work. It it the steps 1 and 2 I would like to change to something better.
What is a more efficient and vim-like sequence?
If you want to search for the word under the cursor
Ctrl-F will do the trick.
Or you can use Vim's * command, which effectively does the same, but jumps to the next occurrence right away by default.
Otherwise
If you need to use the search field for whatever reason, then the standard Vim way to copy stuff to the clipboard works, so you can yank into the * or + registers. The steps will then be:
Select text
"+y (you can create a shortcut for this combination if you want)
Ctrl-Shift-F, Ctrl-V
See also: How to make vim paste from (and copy to) system's clipboard?.
Having said that, the more obvious approach might be to use Vim's built-in search features, so after selecting the text, the remaining steps would be y: (yanking selection to the default register and opening the command-line) then / or ? (search forward or backward), then <C-v> (pasting the yanked selection to the command-line - this works only in the VSCode plugin, while in Vim you should use <C-r>").
I'm new to VIM so there might be a better way using VIM commands but for now this works pretty well.
Go into insert mode with i than select the word you would like to search for (I'm using the mouse) and than just press ctrl + f. Your search window will open as usual containing the selected word in it.
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 am trying to paste a string I copied from a webpage in vim. I know that the string is copied in the system clipboard. My vim returns 1 when I run the :echo has('clipboard') command, so I typed :set paste, then positioned the cursor to the desired spot and hit "*p, but this doesn't seem to paste my whole selection. I copied to the clipboard Vader(father figure) but it only pastes Vader. Or is it pasting this because the word behind the cursor is Vader? And finally, what is the easiest way to paste something in vim from the system's clipboard?
I mention that I am using Ubuntu 14.04 (if this has any relevance).
I always use Ctrl+Shift+v in Insert mode, when pasting from system clipboard after doing set paste. Never had any problems doing so.
Otherwise you can use the vim-unimpaired plugin by tim pope and use the yo key mapping set by the plugin to paste. Using yo automatically sets the paste option and after you paste and leave Insert mode, it automatically toggles the set paste option.
Have this line in your .vimrc
set pastetoggle=<F2>
So whenever you press F2 in insert mode you can paste normally with no problems.
For more information refer here.
You only need to set paste if you intend to paste while in insert mode using the middle mouse button or any shortcut your terminal provides.
Now, it is possible that the register you're looking for is quote+. To confirm that just run :registers in order to view the contents of all registers.
I would also advise you to read the following help section :help x11-selection.
I'm currently using the system clipboard in vim as default register in combination with a clipboard manager like Diodon or Klipper (for KDE).
Add this to your vim configuration ~/.vimrc
" Use the system clipboard for yank / delete / paste operations
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
endif
With this configuration vim copy/paste operations (in both directions) behave just like in any other graphical editor (the if has ('unnamedplus') assure that this behaviour is enabled only if vim is compiled with the +clipboard option otherwise behaves as default).
Note: on Windows and MacOS using unnamed or unnamedplus is equivalent.
On Linux are two different entities:
unnamed register is the selection buffer (try to select something with the mouse and then center click or click both sx and dx mouse buttons in another place).
unnamedplus register is actually the system clipboard
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.
I copy some code from one part of one file to another part in vim, I find that, there are line numbers in each line and the format is gone, how to set correct format as origin ?
like this:
40 root /opt/release/current/public;
67 41 passenger_enabled on;
68 42
If you have line numbers, I'm quite sure you are not using Vim's yank/put operations (these will never copy the linenumbers, foldcolumn, icons etc) because in terms of the edit buffer, they don't exist.
My guess is you are working in a terminal emulator and using the mouse to copy stuff to the clipboard, which possibly selects the 'extraneous' room of the screen (including virtual spaces at the end, line numbers, fold markers etc)
You might have luck setting
:se mouse+=a
in order to get the behaviour of the mouse like you expect it. Otherwise, do the selection with V<movement>...y (y for yank, which corresponds to 'copy')
Then on the destination use p (put at cursor), or P (put before cursor)
Let me know if that helped or you need more info
In case anyone wants a quicker way (on Linux anyways), I have noticed in vim you can hold down ctrl and drag over the region you want to copy and you'll avoid the line numbers and select the part you want.
Steps:
ctrl and drag over area
release ctrl
copy (either keyboard shortcut or right click)
In normal mode, type :se nonu
This is the easiest way to remove the line numbers and you will be able to copy the text without the line numbers.
A permanent solution for this is to add the below code at the end of your .vimrc file located in your home directory.
se mouse+=a
By adding this you will be able to select only text and not the line numbers as shown in below image:
If you are not getting your .vimrc file in your home directory (i faced this problem), type the command :scriptnames in vi editor, it will display the location of your .vimrc file. Reference
On Mac: I found out that you can select the desired area with Option+Command and copy paste it to another editor.
All the previously entered solution are very good one. However, sometimes your are using vim on a remote server (so you cant copy to your clipboard using "+y). Often terminals support copy paste operation.
I use vim to output visual selection to a new shell where I can copy text using terminal feature:
:'<,'>w ! bash -c cat
Then I can easily copy the output.
Same pattern for pasting in vim:
:r ! bash -c cat
Then I paste and send EOF to cat using Ctrl+d. This method also avoid reindenting the text you paste (Note: you can disable automatic indentation using :set pi!).
Have a look at the pastetoggle option sometimes set to F11.
As an alternative you could always write the section you want to copy into a temporary file
(ma, goto end line then use :'a,.w tempfile) then read it into the second file.
For further investigation you might want to look at the autoindent option.
On Windows VIM GUI: :set nu and then hold down Ctrl-Shift while
highlighting the desired text with the mouse. This yanks the line numbers
into the buffer.
On Windows using Putty, I have noticed in vim you can hold down ALT and drag over the region you want to copy and you'll avoid the line numbers and select the part you want.
Steps:
Press and Hold ALT
Drag over area
Release ALT
Copy using CTRL+Shift+C (or right click if that is turned on)
Variations:
The specific key may be different based on your specific set up.
If ALT does not work, try the following keys instead:
CTRL
CTRL+Shift
ALT+Shift
Note:
If anyone knows of any other key combinations that have worked for them let me know and I will update this answer with them.
I mapped the below command to a key.
It strips the whitespace around the copied line numbers.
It ignores the line text and any blank lines behind.
:1,$s/^\s*[0-9]\+\s//\|1,$s/^\s*[0-9]\+\n/\r/<cr>
You can also consider using sed and pbcopy to copy the lines to a clipboard, where you can paste to another terminal or apps outside of vim.
sed -n <line start #>,<line end #>p <file name> | pbcopy
simplest way just: $ cat "your file"
and then just copy it from your terminal without numbers