Solved

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

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

808 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