LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-03-2004, 02:13 AM   #1
blackzone
Member
 
Registered: Jun 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, 02:17 AM   #2
blackzone
Member
 
Registered: Jun 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, 03:13 AM   #3
r0b0
Member
 
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, 03:23 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

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

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


Reply



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 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
2 part question: Speeding up MDK9.1/GNOME question wardialer Linux - Newbie 6 10-14-2004 03:16 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 12:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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