LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-17-2005, 12:37 PM   #1
frostillicus
Member
 
Registered: Jul 2004
Location: Florida
Distribution: Slackware
Posts: 32

Rep: Reputation: 15
saving vi buffers


i want to save a vi buffer to a new file. i can do

"ayy to yank the line into buffer a

and

:30,60w file

to write lines 30-60 as a new file. i would like to combine them to do something like:

:"aw file

where the buffer a is written to a new file. i can get by with the lines command but really i'm looking to use visual mode to select/create the buffers and then save them as new files.

thanks in advance.

Last edited by frostillicus; 04-17-2005 at 12:38 PM.
 
Old 04-18-2005, 10:14 PM   #2
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 18, 19, RHL 5.2
Posts: 546

Rep: Reputation: 43
vi allows you to work with multiple files at a time. You can do this at the start by typing vi file1 file2 file3. You switch between files using :n for next. It also allows you to open another file on the fly by first saving the current file we'll say filea with :w and then using :e fileb to open another file. vi remembers two filenames current % and alternate #. To get back to filea when you are done with fileb you save fileb :w and then type the command :e#.

The way you can save buffers to another file is by opening another file in vi and then copying the buffer to the new file. For example, I open fileabc, perform some edits, and yank part of it to buffer a. After saving fileabc with :w, I open filexyz with the command :e filexyz. (Note: you must save the current file before switching to another file) The buffers remain intact because we never closed vi. So at this point you can use :pu a to put the contents of buffer a into filexyz after the cursor. Save filexyz with :w and then you can switch back to the other file using :e#.

Bill

Last edited by wmakowski; 04-18-2005 at 10:16 PM.
 
Old 04-19-2005, 12:46 AM   #3
frostillicus
Member
 
Registered: Jul 2004
Location: Florida
Distribution: Slackware
Posts: 32

Original Poster
Rep: Reputation: 15
thanks for the response, it cleared up several things for me.

editing an working in vi definitely gets faster and easier the more you work with it, i can only hope the opening/editing of multiple files does likewise. so far i have found that the vi method stinks, i don't like it. why we can't just save a buffer to a new file escapes me and really crimps my style. but the way i figure, if you're doing something in vi and it's not easy then most likely you're not doing it the right way... so it's probably just me....
 
Old 04-19-2005, 08:06 AM   #4
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 18, 19, RHL 5.2
Posts: 546

Rep: Reputation: 43
Yes, very true about vi. When I first used it I thought what a cryptic and nasty way to edit a file. However, if you take the time to learn it you can move around very fast and it becomes second nature. Think about all the time used by taking your hand off the keyboard to move your mouse and then bringing your hand back to the keyboard. To understand vi's development you have to look back to when keyboards did not have arrow keys or a number pad. They had to move around some way. vi was a breakthrough compared to ex or edlin the old DOS editor.

Bill
 
Old 04-19-2005, 12:04 PM   #5
frostillicus
Member
 
Registered: Jul 2004
Location: Florida
Distribution: Slackware
Posts: 32

Original Poster
Rep: Reputation: 15
yep, the operative words being, "if you take the time to learn it." i had been using vi for a while but didn't really take the time to learn the mnemonic combinations, the delete and arrow keys worked while in insert mode so i just used those. it was only after i made a concerted attempt to learn the h,j,k,l, ^, etc., keys properly did things really get going. it took a while, but now i actually prefer it and think it is faster than with a mouse.
i am close to being able to totally dump kedit, if i could more adequately solve the buffers issue then i would... the open/close methods given by wmakowski work fine for most situations, however, like yanking a chunk from one file and inserting it into another, it's only when trying to save a named buffer as a new file does the sequence seem convoluted, and even then it is still workable. so i say, hooray vi!!

Last edited by frostillicus; 04-19-2005 at 12:08 PM.
 
Old 04-19-2005, 09:03 PM   #6
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,747

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
Remember, you still have the options of emacs and jed.
 
  


Reply


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
UDP Buffers awksquawk Linux - Networking 1 11-18-2005 04:41 AM
[C++] buffers streams Ossar Programming 1 06-14-2005 12:27 PM
mplayerplugin buffers to 99% then nothing happens vavoem Linux - Software 9 10-13-2004 01:03 AM
About buffers? eshwar_ind Programming 2 04-30-2004 05:13 AM
eth1: no RX buffers subhasis_ray Linux - Networking 1 11-11-2002 06:45 AM


All times are GMT -5. The time now is 01:10 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration