LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-31-2011, 04:16 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,520

Rep: Reputation: 51
Vim: jumping from file c1 to file c2 without saving c1 first.


Kernel 2.6.21.5, slackware 12.0
Vim 7.1

Hi:
I do 'vim c1 c2' and I begin copying parts of c2 to c1 (yank, put). Now, each time I go back to c2, I must save c1 first. But it happens that I'm not sure I want to save it. Is there a way to go back and forth between c1 and c2, making changes to one of them, without having to write to disk before switching? Notice the changes must be kept. Thanks.

Last edited by stf92; 07-31-2011 at 04:35 PM.
 
Old 07-31-2011, 05:09 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Hello stf92,

as far as I know vim can only open one buffer simultaneously. Therefore you'll have to save a buffer before editing another one.

It is possible to split vim's windows and edit every file in a separate window, afaik this should work for you.

Markus
 
Old 07-31-2011, 06:51 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,520

Original Poster
Rep: Reputation: 51
Thank you, Markus, for your useful info.

Enrique.
 
Old 07-31-2011, 07:00 PM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
You mean using ":e"? As far as I know you can switch woutout saving using ":e!". The reason it doesn't let you by default is because it's easy to forget that you have an unsaved buffer.

Also, you can use tabs instead.

Create a tab:

:tabnew optional-filename

Next tab:

gt

Previous tab:

gT
 
1 members found this post helpful.
Old 07-31-2011, 07:15 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,252

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
A good HOWTO on vim buffers http://vim.wikia.com/wiki/Vim_buffer_FAQ
 
Old 08-01-2011, 04:48 PM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,520

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by MTK358 View Post
You mean using ":e"?
No. By the use of ctrl-^, or :next.

@chrism01: Thank you for the link.

In connection with the present issue, I would like to have this question answered: what does vim do when the file to edit is larger than the amount of available memory?
 
Old 08-01-2011, 06:45 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,252

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Well, by default vim normally creates a backup copy eg in /tmp; usually filename.ext~ which it then uses for recovery if you get interrupted.
I think it either uses that or the version in RAM would have some of it swapped to swap?
In any case, would you really want to be using vim on a file that size?
I'd got with sed/awk/Perl if its that big.
How much RAM do you have?

If you really want to know the definitive answer, try the home site http://www.vim.org/

Last edited by chrism01; 08-01-2011 at 06:46 PM.
 
Old 08-01-2011, 07:57 PM   #8
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,520

Original Poster
Rep: Reputation: 51
No, no, no (thanks for the link). I asked because I had a text editor, when working in MS-DOS v. 5.00, which could load more than one file. Changes could be made to these files and one jumped from one to the other by a key combination stroke, with no need to save the current file before jumping. This editor loaded all files into RAM (it was useless for files bigger than available RAM).

I thought this could be the reason for that easy behaviour, but now I see it is nonsense. What I can't understand is what's the trouble in jumping to another buffer. Thanks for your post.

Last edited by stf92; 08-01-2011 at 07:58 PM.
 
Old 08-01-2011, 09:29 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
There's no trouble...
:next!



Cheers,
Tink

Last edited by Tinkster; 08-01-2011 at 09:31 PM.
 
Old 08-02-2011, 09:23 PM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,520

Original Poster
Rep: Reputation: 51
But I loose the changes! Let's see:

$ cat f1
aaa
$ cat f2
bbb
$ vim f1 f2

Say f1 is in buf1 and f2 in buf2:
buf1: aaa
buf2: bbb

I make changes in buf1:
buf1: aaac
buf2: bbb

I now do :next to go to buf2. But I can't, unless I save buf1 first or do :next! and lose the changes to buf1.

Now, buf1 and buf2 are two separate spaces in memory. Why can't vim just jump to buf2? What does it matter if buf1 had a change made? Because vim was written that way? The logical thing is that the user can maintain two buffers, inspecting or modifying whichever he wants of them, even if someone comes and steals the hard disk. I am assuming f1 and f2 are small enough so that buf1 and buf2 fit in RAM.
 
  


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
vim file.tex !latex file.tex & pdfdvi file.dvi & xpdf -remote sname -reload Mol_Bolom Linux - General 0 07-09-2009 08:46 PM
Linpus Fedora after saving files to file system, CAN'T open FILE SYSTEM from desktop! remiwa Fedora 2 01-07-2009 08:28 AM
vim always says swap file already exists for a particular file leftty Linux - Software 1 09-13-2008 02:53 PM
saving file blackzone Programming 5 01-21-2005 06:51 PM
Is there any app to convert emacs's syntax highlight def. file to vim's def. file ? cyu021 Linux - Software 0 10-06-2004 12:02 AM


All times are GMT -5. The time now is 01:38 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration