Solved

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

Posted on 2014-01-20
5
583 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
5 Comments
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 333 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 34

Expert Comment

by:Dan Craciun
ID: 39795012
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 333 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 37

Accepted Solution

by:
Gerwin Jansen earned 167 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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 …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now