Saturday, May 16, 2015

Re: vim how to edin same file in different window

On Sat, May 16, 2015, Gary Johnson wrote:
> On 2015-05-16, Christian Brabandt wrote:
> > Hi Daniel!
> >
> > On Sa, 16 Mai 2015, Daniel Dimitrov wrote:
> >
> > > I have splited the window in 2 different views by Ctrl+W, V but what i
> > > want to achieve is to edit them separately without affecting the other
> > > and after that save them with different names. Thanx in advance
> >
> > After splitting do a
> > :saveas name
> > in each window to make sure, that each window has its own buffer with
> > its own name for the original buffer.
> >
> > (Obviously it would be better to use a different name in each window ;))
>
> When I try that, the buffer name changes in both windows. The
> windows are just different views into the one buffer.
>
> The way I usually do that is yank the buffer into a register, open a
> new buffer in a new window, paste the register into that buffer, and
> delete the empty first line, e.g.,
>
> ggyG
> :new
> p
> kdd
>
> Or you could read the file into the new buffer, e.g.,
>
> :new
> :r#
> :0d_
>
> Regards,
> Gary

A shortcut would be to, before splitting windows or starting new
buffers, follow these steps with the original buffer active:

1. :w (with filename if it hasn't already got one. IMPORTANT)
2. :sav filename2
3. :sp # (or :vsp # for vertical)

:sav automatically saves the current buffer as a new file _and_ opens a
buffer in Vim for that file; that new buffer is made active. Then :sp #
opens a split on the alternate file, which is the file from which the
current buffer was cloned. This puts the original file's window above or
to the left of the clone, unless :bel is prefixed in step 3.

Step 1 is important because, if you've made changes in the original
buffer, the changes will end up getting saved to filename2, and lost in
the original buffer. (Although I suppose sometimes one might intend to
do this, if the buffers aren't meant to be identical to begin with.)

--
Eric Christopherson

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment