Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-03-2004, 03:13 AM   #1
Registered: Jul 2004
Posts: 256

Rep: Reputation: 30
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.
Old 09-03-2004, 03:17 AM   #2
Registered: Jul 2004
Posts: 256

Original Poster
Rep: Reputation: 30
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?
Old 09-03-2004, 04:13 AM   #3
Registered: Aug 2004
Location: Europe
Posts: 608

Rep: Reputation: 50
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
Old 09-03-2004, 04:23 AM   #4
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392
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.
Old 09-03-2004, 09:31 AM   #5
Gentoo Developer
Registered: Feb 2004
Location: Fort Lauderdale FL.
Distribution: Gentoo
Posts: 3,291
Blog Entries: 5

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 05:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 02:51 PM
2 part question: Speeding up MDK9.1/GNOME question wardialer Linux - Newbie 6 10-14-2004 04:16 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 03:02 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 01:53 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:16 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration