Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm running ubuntu on my laptop. I'm using vi to edit large files. What command do I use in vi to cut blocks of the file and output them as a separate files?
If you demand vi feeling, I strongly recommend vim instead of plain vi.
It offers a visual mode that is quite powerful and works really intuitive!
Having done so, it goes like this:
* Press v to enter visual mode or V to enter visual line mode (you'll see the difference)
* make your selection using hjkl or cursor keys
* press x to cut your selection into the the "clipboard" (register in vi terminology) or y to copy it instead (This exits visual mode)
Here you are unclear in what you want to do: Do you want to write these blocks to newly-created files, or do you want to paste them into other files?
* You paste your copied or cut block of text with p
If you want a selected region to be saved in a seperate file, do this:
* With your selected region still active type : to enter command mode
* Type w new-file-name.txt
It will look like this:
:'<,'>w new-file-name.txt
This means, your currently selected region will be written into new-file-name.txt
why do people stil use vi when ther are other easy to use editors like nano , emacs etc? i find it really difficult to use .. is there anything special about vi ??
why do people stil use vi when ther are other easy to use editors like nano , emacs etc? i find it really difficult to use .. is there anything special about vi ??
vi is exceptionally easy to use -- once you have learned the basics. Once you know the basics you can easily do more and more advanced stuff as a simple logical extension of what you already know. People use it because it's extremely powerful, quick, and easy to use. That's especially true for structured files but holds true for almost everything I do.
As for the original question, he's got answers enough already.
Personally, I use m instead of visual mode (mostly because some of my systems don't have vim and probably never will).
Code:
ma2}:'a,.w newfile^M
It's not that hard. Actually, since it makes use of all the normal movement and marking commands you're using all the time... it takes minimally more time to do that than to do anything else.
(Note, the above starts at the current line, and writes two paragraphs to the newfile the ^M stands for the <ENTER> key)
As more detailed explanation.
Code:
m[ark point]a2}[go down "2" paragraphs]:'[from point]a,[to].[the current line]w[rite]newfile^M[filename and return]
Tanx. Your responses have been very helpful. I like vi because it pretty easy to use. There are probably countless better editors available, but vi suits me fine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.