Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: could I copy text from vim and paste it to shell prompt using only the keyboard?

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.

like image 389
user1129812 Avatar asked Oct 20 '22 13:10

user1129812


1 Answers

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.

like image 157
Atropo Avatar answered Oct 29 '22 17:10

Atropo