Solved

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

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

695 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