1

I have set up ubuntu-14.10 to boot up in text mode (cli) and I start gui with the command sudo service lightdm start then toggle between gui and cli mode with Alt+ctrl+F1 (to get into cli) and Alt Gr + LEFT ( to get into gui mode).

How can I paste the selected text from gui and toggle to cli mode and then paste it there (especially in vim)?

Note- I have tried ctrl+shift+v , ctrl+shift+insert,ctrl+y ctrl+v but none of them are working. I have modified my .bashrc so that it starts tmux inside cosole upon startup. I don't know if this has anything to do with tmux so please guide me?

11
  • I googled a bit and found xsel and xclip but could not get them to work in VTs. – daltonfury42 Aug 23 '15 at 7:51
  • 4
    Copying text GUI to TTY is impossible, AFAIK. You'd need to save it to some file, then open that file in TTY, cat it for example. TTY to GUI is a bit easier. You could open virtual terminal and do cat /dev/vcsX where x is number of tty you want to dump form. Let me know if you want this as an actual answer – Sergiy Kolodyazhnyy Aug 23 '15 at 7:53
  • 1
    i agree, echo "sometext" > somefile in the gui and just $(cat somefile) in TTY and it will run – mchid Aug 23 '15 at 8:06
  • 1
    Can you please explain why is this impossible . I think whatever cut or copied is placed into a temporary place clipboard from where I can paste it anywhere. Isn't it? – 0decimal0 Aug 23 '15 at 10:04
  • 1
    @Serg, why is this so? Is it because clipboard is part of X server which is contained in the VT in which GUI(X11) is running, and hence is inaccessible from outside? Just wondering. – daltonfury42 Aug 23 '15 at 18:40
2

How can I paste the selected text from gui and toggle to cli mode and then paste it there (especially in vim)?

If your goal is to go directly from GUI to TTY and paste, that's impossible. You have to have something in the middle, something in common between tty and gui.

Terminal multiplexers such as screen, tmux, and byobu allow creating shared sessions. That means, if you run screen in graphical terminal emulator, then login to TTY1 and attach yourself to the shared session, everything you type in GUI will show up on TTY1 as well. The two terminals will behave as one

Note: taking screenshot form TTY is difficult, so for demonstration purposes I will create shared session between two GUI terminals.

Of course, the 3 multiplexers don't come with Ubuntu by default. If you want to get either one, install them with sudo apt-get install app-name. Note, that installing byobu gives you all 3 together.

GNU SCREEN

  1. Start screen session in TTY1.
  2. Press Ctrl+a, then :. type multiuser on enter image description here
  3. Return to GUI. Open terminal emulator. Type screen -ls to list sessions.

  4. Type screen -x and the id of the session you found with -ls command.

enter image description here

Now you should have 2 shared screen sessions enter image description here

TMUX

  1. Start tmux in TTY1. Return to GUI
  2. Open terminal emulator.List sessions with tmux list-session enter image description here
  3. Attach GUI tmux session to TTY1 session with tmux new-session -t X , where x is the number of the TTY1 session.

enter image description here

BYOBU

Simply open byobu session in TTY1 and then go to GUI and open another byobu. They attach automatically.

Sources and Suggested Reading

Share existing tmux session

GNU Screen Splitting

HowTo Share A Terminal Session Using Screen

http://i.stack.imgur.com/RlzTj.png

10
  • Hi, this creates a shared session , whatever I type on terminal appears on the tty that is cool but it doesn't happen otherwise ,i.e I can do cut , copy paste or anything on terminal and it appears on tty but I can't do the same thing in tty. My whole point is copying from gui and pasting in cli ( either in vim or elsewhere). This solution works for the appearance's sake but it doesn't provide any capability in tty . If this is completely not possible then that can be an answer . I am a novice in linux so I don't even know if its possible or not . Just looking at the posssiblities . thanks :) – 0decimal0 Aug 24 '15 at 4:10
  • Well , shared session allows you to copy and paste. If you want to use mouse in tty or select text without using shared session, then it doesn't work. Sorry. TTY is just text only and simple features – Sergiy Kolodyazhnyy Aug 24 '15 at 4:14
  • All the above commands which I mentioned didn't work for tty . Can you suggest any key combination or anything which I can use there to paste and copy. All those commands work for terminal opened in gui mode . – 0decimal0 Aug 24 '15 at 4:23
  • Those key combinatioN's work only for terminals in GUI. There are some shortcuts for tty but they are limited. Let me give you link in a second – Sergiy Kolodyazhnyy Aug 24 '15 at 4:27
  • Here one and two. Let me know if this helps you. These work in tty. But these help you move around the command line. But these dont help copying from GUI to TTY. – Sergiy Kolodyazhnyy Aug 24 '15 at 4:32
0

To my surprise it is actually possible. First some setup:

  1. Install xclip.
  2. Switch to the virtual terminal with Ctrl-Alt-F1.
  3. Run alias pc='$(xclip -display :0 -out)'.

Now, assuming you've copied some text and changed back to the VT:

  1. Type (don't run) pc.
  2. Press Ctrl-Alt-e. If this doesn't do anything immediately* then do the following:
    1. Switch back to X with Ctrl-Alt-F7.
    2. Switch back to the VT with Ctrl-Alt-F1.

What happens in the last step is that the shell-expand-line readline command replaces the command line with the output of the pcalias.

You may also want to add the alias to your ~/.bashrc for convenience.

* When copying text in Firefox the xclip command blocks. However, after selecting text in an XTerm window it didn't.

I am not using tmux.


You can use the same method to paste into vim: just type vim - <<'EOF', press Enter, type pc, press Ctrl-Alt-e and Enter, and finally run EOF.

2
  • The xclip printed the clipboard contents but how can I paste it there ? – 0decimal0 Aug 23 '15 at 10:59
  • I have edited my question to be more clear . Actually if pasting would not be possible in vim in cli mode then its quite useless, at least for me . It would be so helpful of you to get me there . thanks – 0decimal0 Aug 23 '15 at 18:57

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.