?
Solved

How to Copy and Paste a Line in a file In Unix Using VI Editor?

Posted on 2014-01-20
5
Medium Priority
?
603 Views
Last Modified: 2014-01-20
I have a file open in Unix using VI. I need to make a copy of an existing line and paste it to create a new line and then just make a change to that line so I don't have to type the entire line from the beginning.

what is the command to copy a line and then paste itusing VI?

Thanks!
0
Comment
Question by:matrix0511
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 1332 total points
ID: 39795011
copy is yank
To copy one line use

yy
in the command mode

To paste use
p

in the command mode
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39795012
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 1332 total points
ID: 39795023
You can also use visual mode to highlight
Use
v  - for single line
V - for multiple lines

The use arrow keys to highlight the text then use single y to copy

and then adjust your cursor and press p to paste after the current cursor location or P to paste before the current cursor location
0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 668 total points
ID: 39795213
As said already, y is for yanking (copying lines), if you want to copy more than one line, just add a number like this:

2yy
(copies 2 lines)

then move your cursor and use:

p
(to paste 2 lines)

If you want to copy just a few words:

y3w
(copies 3 words from current position)

or from current position to end of line:

y$

Lots of possibilities :)
0
 

Author Closing Comment

by:matrix0511
ID: 39795243
Thanks guys!
0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Fine Tune your automatic Updates for Ubuntu / Debian
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question