Solved

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

Posted on 2014-01-20
5
592 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 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 35

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 38

Accepted Solution

by:
Gerwin Jansen, EE MVE 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

696 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