Friday, April 7, 2017

Re: RFE: enable gvim to open a buffer or tab in a new window

On Thursday, April 6, 2017 at 6:54:10 PM UTC-5, L. A. Walsh wrote:
> Jacky Liu wrote:
> > Just in case, you know that the split columns and lines in Gvim can be
> > dragged by mouse right? And this is still not what you want ?
> Thanks Jacky, but no. I _do_ use that to adjust the
> split lines after the split, but just now, I was editing
> 2 files (C++ & header: file.cc + file.h). They were each
> in a tab with line numbering + fdc=1 turned on and each
> had 80 columns for the text. (I try to keep my windows
> sized @ 80 columns so I know when I enter code, where it
> is going to wrap).
>
> I was switching back and forth adding some code, then realized
> something was inconsistent, so now I want to see them side by
> side.
>
> If I could drag a tab out and have it display itself in a new
> window, that'd be great -- 2 windows side-by-side, each
> 80-text columns wide.
>

So your goal is: two windows, 80 chars wide, with a different file in each. Let's call them file.c and file.h.

> If I used a vertical split, first problem is I have 2 vertical
> panes with the same file. How do I switch?

That's your first problem, you used the wrong command. The ":vsplit" command takes an argument, you don't need to split the same file. You could do this instead, assuming you're in file.c right now:

":vsplit file.h"

Now you have a split view of both files.

That's the basic usage. If you also want to preserve your first view of the file, i.e. if you want to rapidly switch between file.c in its own tab, and file.h in its own tab, and also file.c and file.h together in a view, then do this instead:

":tab split | vsplit file.h"

Or more succinctly since you don't like typing:

":tab sp | vsp file.h"

or even:

":tab sp | vsp %:r.h"

This last form is useful for long file names, like "this_is_a_really_long_filename_i_do_not_want_to_type_or_even_tab_complete.h". The "%:r" expands to the current file name (e.g. "file.c") with the file extension removed (e.g. "file")

Actually since you already have file.h open, it's already loaded in a "buffer". So you could use ":tab sp | vert sb file.h"

Note that tab completion works on all the file names above, especially the buffer version immediately above which will work even if the files are in different directories or something.

> If I click on the
> other tab, it switches to the ".h" file & 1 vertical tab.

Vim is designed for keyboard use. It can be used more powerfully and more efficiently without using the mouse for most things.

Vim tab pages are not the same as tabs in other programs, they are individual workspaces containing one or more windows, they are NOT locked to a file.

> So first I need to figure out how to get my 2nd file into
> one of the vertical tabs (the other tab would have my .cc file).
>

See above.

> Now say I have different files in each vertical column --
> but now the vertical columns are 38 columns wide each, right?
>

Yes they would be, if you started with a 80-character wide window. But the top-level window is easy to resize with the mouse or even by maximizing the window. I almost always use gvim maximized. If you want to keep a floating window instead use the mouse to resize or set the 'columns' option to the desired size.

> Line numbers are taking 3 columns, fdc is taking 1 column,
> so splitting the text window (80 columns, but reserving 4
> columns for the 2nd vertical pane's numbers+fdc), gives
> me 76 text columns so 38 columns each (maybe more if
> window decorations take up space).

If you want to turn off line numbers, etc. to save space, that is easy to do. In one window: ":set nonumber foldcolumn=0". In both: ":windo set nonumber foldcolumn=0".

If you use the suggestion above to set up a separate tab page for the split view, then you can even keep the numbering on in the original tab for easy reference.

>
> Then I need to move the split-marker to center --
> not the easiest thing to eyeball.
>

It should automatically be centered as soon as you create it. If it's not, a typing CTRL-W followed by = will make the window sizes equal. Or ":wincmd =".

> That takes time and a lot of work just to get the files displayed
> side-by-side.
>

":vsp file.h" is not a lot of work or time.

":tab sp | vsp file.h" is barely more.

I can do both of these faster than dragging a tab anywhere with a mouse.

> When I'm done, I need to undo all those window size changes and
> put the 2nd file back in its tab.
>
> I wouldn't know how to begin to do that all by keyboard.
>

By creating a third tab as I detail above, undoing all the window changes and such is as easy as ":tabclose" or ":tabc".

Of course you may still have a maximized application window to deal with, if you don't like that.

>
> The easiest thing I end up doing now is quiting and editing
> the files separately (and they both automatically come up
> the right size).
>

Is maximizing for the split view and then restoring the application window an option? If not is there a reason you need specifically 80-character application windows? Or do you just like that size?

> Do you see how that can be a major time waste and hassle, vs.
> dragging out the tab and either having it auto-spawn a window
> if dropped, or into a 2nd window, if I need to have one open
> first.
>
> Using only the keyboard, I don't think it would be easy to do
> quickly -- if it could be done at all.

--
--
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