Copy to system clipboard instead of vim buffer
Solution 1
You can have Vim use the clipboard instead of the default register for yanking, putting, etc., by adding this command to your ~/.vimrc:
set clipboard+=unnamed
See
:help clipboard
:help 'clipboard'
Solution 2
You first need to see if vim is compiled with clipboard support, run vim --version | grep clip
and see if there is a +
or -
in front of clipboard
and xterm-clipboard
.
If it has clipboard support, copying from and pasting into the *
or +
registers should use the system/X11 clipboards, so "*yy
would copy a line and "*p
would paste it.
In Ubuntu 10.10 you can install vim-gnome to have clipboard support compiled in.
Solution 3
have a try :
"+y and "+p
this works for me, on Ubuntu.
Solution 4
The default VIM in Ubuntu is vim-tiny, which is not compiled for system clipboard support. You need to install the full VIM and the Gnome GUI to get clipboard support:
sudo at-get install vim-full vim-gnome
After you install those two packages you can then use the commands that Akira and wliao mentioned.
Related videos on Youtube
Jim
Updated on September 17, 2022Comments
-
Jim over 1 year
This program is supposed to accept 10 single digit numbers and then output the largest number entered. The program runs fine with the exception that I get the output screen after each number entered. The output is correct. I cannot figure out how to get the output screen to display only after all 10 have been entered.
package largest; import javax.swing.*; public class Largest { // Main method public static void main(String[] args) { // Declare variables int largest = 0; int counter = 0; int number = 0; // Condition statement to repeat loop until 10 digits are entered while (counter < 10) { // Prompt user for input String input = JOptionPane.showInputDialog(null, "Enter a number between 0 and 9: "); // Try-Catch statements to check and handle format errors try { number = Integer.parseInt(input); } catch (NumberFormatException e) { number = -1; // Triggers the error message } // Checks to make sure number is a single digit if (number >= 0 && number < 10) { // Determines if the number entered is the largest if (number > largest) { largest = number; } // Increases counter variable by 1 with a valid entry counter++; } // Display error message else { JOptionPane.showMessageDialog(null, "Your entry was not a single digit, please re-enter.", "Error", JOptionPane.ERROR_MESSAGE); } // Display the largest number JOptionPane.showMessageDialog(null, "The largest number entered is: " + largest, "Results", JOptionPane.INFORMATION_MESSAGE); } } }
-
sgbj over 10 yearsMove the statement that displays the largest number outside of your while loop (in other words, move that last statement down a few lines).
-
Jim over 10 yearsAren't I the idiot tonite. Cannot believe I did not see that. Much thanks @sbat!
-
Nathaniel Ford over 10 yearsPlease create slightly more descriptive question titles and avoid walls of code; you should provide the minimum amount that demonstrates the problem.
-
-
Owais Lone over 13 yearsIt doesn't work. Works fine in Vim itself but does not seem to affect the system clipboard.
-
Owais Lone over 13 yearsOh, it's not working because my version is 7.2 and this seems to be supported in 7.3 only.
-
Owais Lone over 13 yearsI tried both this and the method above but I can't get it to copy to system clipboard. It works fine inside Vim though.
-
harrymc over 13 yearsThen why not upgrade?
-
Breno Macena about 11 yearsThis one works for me, not the * version. Why are people reporting different things?
-
Breno Macena about 11 yearsIt works for me exactly as described, except using +. "+yy.... Why?
-
Breno Macena about 11 years@akira Ahhh, that makes sense. Mine is compiled with a +. :)
-
Jim over 10 yearsThanks @Mauren. I am brain dead tonite, should have seen that.
-
Mauren over 10 yearsSome ice cream and some sleep might help :)
-
cledoux about 9 yearsI had to use
set clipboard+=unnamedplus
as per vim.wikia.com/wiki/Accessing_the_system_clipboard. The*
register doesn't copy to my clipboard when I'm running vim from a terminal (which is always). -
hodgkin-huxley about 8 yearsFor Arch (around 2016-04), I did:
set clipboard=unnamedplus