Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yank lines from one file in vi ( not vim ) to another?

Tags:

vi

copy

paste

I'm used to VIM and usually I split screen with and open another file, yank the text into the second one. However I'm dealing with a legacy server which only has vi, how could I either open multiple files with it if it doesn't support split views or copy text from one file to another ( 2 separate vim instances I guess ).

I don't think this server has 'screen' enabled and I have limited access so I can't just go installing things.

like image 721
meder omuraliev Avatar asked Sep 21 '09 16:09

meder omuraliev


People also ask

How do I copy a line from one file to another in vi?

The vi p and P commands "put" the line back into the file just after (p) or just before (P) the line on which the cursor is resting. Directions: Press the ESC key to be sure you are in vi Command mode. Place the cursor on the line you wish to copy.

How do you yank multiple lines in vi?

To place the yanked line in a new line above the cursor, type P . The yy command works well with a count: to yank 11 lines, for example, just type 11yy . Eleven lines, counting down from the cursor, will be yanked, and vi indicates this with a message at the bottom of the screen: 11 lines yanked .

How do you yank text within vi?

To copy text, place the cursor in the desired location and press the y key followed by the movement command. Below are some helpful yanking commands: yy - Yank (copy) the current line, including the newline character. 3yy - Yank (copy) three lines, starting from the line where the cursor is positioned.


2 Answers

open one file in Vi, yank text, then use

:e another_file

to open another file, and paste.

like image 72
nothrow Avatar answered Jan 03 '23 11:01

nothrow


Assuming you are already inside a file where you have to paste text.

  • :w (first save the current content)
  • :e file2
  • goto location and yank (say yy)
  • :b 1 (goto buffer 1, i.e. return back to original file)
  • goto location and paste (p)
like image 34
VineetChirania Avatar answered Jan 03 '23 12:01

VineetChirania