How to paste the text selected from gui mode after switching into cli mode?

by 0decimal0   Last Updated May 16, 2019 02:02 AM

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?



Answers 2


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.

l0b0
l0b0
August 23, 2015 10:13 AM

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

Sergiy Kolodyazhnyy
Sergiy Kolodyazhnyy
August 23, 2015 20:08 PM

Related Questions


Updated August 30, 2015 03:01 AM

Updated October 19, 2015 18:01 PM

Updated September 26, 2017 19:02 PM

Updated May 08, 2015 12:07 PM

Updated October 09, 2015 17:01 PM