I am trying to copy a large block of code (with indentations preserved) from one vim terminal into another. I was wondering if there was a straightforward way to do this?
Would this be considered a vim functionality, or a property of the terminal?
A lot of things are missing from your question: Which terminal emulator do you use? On which platform? Is Vim compiled with clipboard support?
I'm on Ubuntu, running Vim 7.3 with clipboard support in Gnome Terminal so YMMV.
I'm able to select a block of code with
You might need to do
Also, why do you use two different Vim instances in two different terminal windows when Vim has split windows buit-in?
You should be able to copy from one terminal holding
There are several pieces to this puzzle that must work-together to make copy/paste work.
First, the "terminal" must have a way to exchange data from one session to another... Most of the time, this is handled by a GUI manager of some sort... (XORG/Windows/etc...) which implements some sort of "clipboard" functionality.
Second, the "terminal" application itself must be able to interact with whatever clipboard interface exists... to keep all "terminals" in sync...
Third, the shell (bash/ash/dash/csh/etc...) needs to be able to access the terminal's clipboard APIs...
Forth, VIM needs to make use of the clipboard APIs provided by the shell it's running in.
Any one of those failures can mean that your application can't make use of any sort of clipboard between terminals.
All that being said... there are some "standardized" API calls for the clipboard... so assuming each bit has done it's job properly, it should work.
Now... there are some handy tricks to simply get the job done without worrying about all the clipboard crap... which is probably what you want to begin with...
VIM will let you copy text and export it to a file and then on another console import the text from that file, and here's how:
First: make sure you're not in "edit" mode... (press escape key) and move the cursor to the place you want to start copying and press the
If you want to paste a copy in the same document at this point... just move the cursor to wherever and press
Now, on the other terminal, simply go to the spot in the file you want to paste into (not in edit mode)... and do a
If you're using a standard terminal such as GNOME Terminal or xterm and a properly-configured Vim, this should just work. That is, you should be able to use your mouse to select the text you want to copy, then click the middle mouse button in the target Vim and the text will be pasted.
If the block is too large to be easily selected with the mouse, you can select the text from the keyboard instead. Move the cursor to the first line of the block, type
If this doesn't just work, the most likely reason is that the Vim you're using in a terminal was not compiled with support for X, so it can't communicate with the X server. You can find this out by executing
If your Vim was compiled with both of those features, the result will be "
If your Vim doesn't have those features but you have gvim installed, one solution is to run gvim in terminal mode as