Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Vim seems nice for most of the times and outperforms other editors in some categories. But what about Copy&Paste? (It seems to me that even MS DOS' EDIT.COM seems to outperform vim in this category.)

Scenario 1: I have a software project, lots of directories and I want to move a function from one file to another. What is the most efficient way to do that?

Scenario 2: I activate indentation. It seems in conflict with multi-line copy&paste. I remember seeing on the internet people suggesting to switch indentation off during this process. At the same time I even saw some weird macros. Is there an efficient solution?

share|improve this question
1  
Hahaha, edit.com > vim. Some nerds are going to be angry with you! –  Tim Jun 22 '12 at 19:12
    
I like to be provocative :D –  Philip Jun 22 '12 at 19:47
add comment

2 Answers

up vote 4 down vote accepted
  1. if you use NERDTree plugin directories are not your enemy and otherwise you can open multiple files in tabs or split the window.

  2. copied text can be pasted from clipboard by "+p and within vim yankin(=copying) and pasting works flawless - not only multiple lines but also blockwise - i don't know if M$ DOS Edit can do that.


I don't know if any text-editor survives more than 20 years in the wilderness if it performs bad at copying or moving text between files.

share|improve this answer
    
NERDTree definitely makes working with vim more fun... I know 2 persons using vim (one of them convinced) and both use it really inefficently... Basically my fingers hurt when looking ;) –  Philip Jun 23 '12 at 11:11
    
the fingers only hurt because the typing speed makes the keys burn ;) –  epsilonhalbe Jun 23 '12 at 11:14
    
I thought it was chronic illness from typing ;) –  Philip Jun 23 '12 at 13:53
add comment

:open the first file, yank, :open the second file, paste. You may want to use a plugin such as NERDTree to locate the second file faster.

To copy-paste between two different instances of Vim: yank in the first file, call :wv to write the viminfo file; in the other file, call :rv to read the viminfo file then paste.

Indendation doesn't matter to Vim's copy-paste. It only matters when you paste data from the X clipboard into a text terminal, because Vim can't tell that this is pasted text and not something you typed. When pasting multiple lines from the X clipboard into a text terminal, first :set paste to turn off all automatic text processing (indentation, abbreviations, wrapping, …).

If you're running Vim under X or in an X terminal and your Vim supports it, you can copy and paste data through the X clipboard. Yank and paste to the * register for the X11 selection and to the + register for the X clipboard. For example, "*42yy in the first file and "*p in the second file.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.