LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   vi question (https://www.linuxquestions.org/questions/linux-newbie-8/vi-question-226026/)

blackzone 09-03-2004 02:13 AM

vi question
 
if I have 2 files, how do I copy a section of one file to the other?

all I know is "yy" for copy and "p" to paste, but that can only be done in same file.

blackzone 09-03-2004 02:17 AM

Also another question about replacement.

How do I replace all string in a file by the other.

right now I use :s1,lastline/oldstring/newstring/g

but the problem is I need to always know the number of line in the file before I can do replacement. Any faster way?

r0b0 09-03-2004 03:13 AM

1. If you use vim, you can have multiple files opened in the same time and copying and pasting operations work fine between them.
2. :%s/oldstring/newstring/g
% means all lines in the file

druuna 09-03-2004 03:23 AM

If opening two (or more) files is not an option, you can do the following.

You have opened the 'master' file and are in command mode:

r!sed -n '2,4p' /etc/passwd

This will put lines 2,3 and 4 from the passwd file into the file you are editing, below the cursor position.

comprookie2000 09-03-2004 08:31 AM

A great program that comes with vim is vimtutor,try it from the command line.


All times are GMT -5. The time now is 04:25 PM.