Question

I am using vim 7.3 on the Ubuntu 12.04 terminal.

When editing a file in vim, I could select some text in visual mode and then use "+y to yank it into the system clipboard. I could then paste the text into ANOTHER Ubuntu terminal (using shift-ctrl-v).

However, if I could have access to only one Ubuntu terminal, I must temporarily leave vim by using :shell to go to the Ubuntu command prompt. After that I find that the yanked text no longer exists in the system clipboard and I could not paste it into the command prompt.

Is there any way that I could retain the yanked text in the system clipboard after using :shell (using keyboard only) ? Thanks for any suggestion.

Was it helpful?

Solution

A workaround could be use a terminal multiplexer like tmux for your remote ssh sessions.

With tmux you can open more panes (or splits) on the same connection, you can work with vim in a pane (split) and the shell in the other.

With tmux you can copy text from a pane (split) to the other. With the standard shortcut Ctrl+b the workflow is this

  1. In the vim pane enter tmux's copy mode mode Ctrl+b[
  2. Highlight the text you want to copy with Ctrl+space
  3. When the selection is complete, copy the text to tmux clipboard with Alt+w
  4. Swith to the console pane in tmux (with two panes would be something like Ctrl+b1
  5. Paste the text in the shell prompt with Ctrl+b]

You can see all the tmux shortcuts by browsing the manual or with Ctrl+b? while inside tmux.

There are some plugins like tslime, vimux and vim-slime that let you interact with a tmux session while in vim, like sending portions of text.

OTHER TIPS

The following works for me with a gnome-terminal in Fedora and vim7.3.

  • Select the text you want, for instance using visual mode.
  • Press Ctrl-Shift-c
  • Then enter ESC followed by :shell
  • Once in the shell press Ctrl-Shift-v

If you also grab a newline when you copy it will execute as a shell command when you paste.

A side effect of this is that by doing :shell if you have vim configure to save .swp files, there will be one left in the current directory and the next time you edit the original file, you will need to deal with vim complaining about finding a swap file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top