Need good tab-page tips on Vim Tips wiki

5 views
Skip to first unread message

Benjamin Fritz

unread,
Nov 26, 2009, 1:16:30 AM11/26/09
to vim_use, vim-l
I sometimes hang out on the #vim channel on Freenode, where use of tab
pages is often discouraged in favor of efficient use of the
buffer/argument lists, split windows, and the 'hidden' option.

Personally, I prefer using tab pages in many circumstances, but have
never really had any specific advantages or features of tab pages that
I can bring up to support my preference.

On the Vim Tips Wiki, we have in the category description of
http://vim.wikia.com/wiki/Category:Tabs an indication that the
category contains tips that "exploit Vim's tab page design to do
clever things you can't do in other editors", but there are very few
tips in this category that actually offer this.

I'm sure there are clever ideas out there that leverage the power of
tab pages in Vim, that are difficult or impossible to accomplish
otherwise. I'd like to add some of these ideas to the Tabs category on
the wiki.

Please add these ideas to the wiki directly, or respond to this
thread. You don't need to make the tip perfect before adding it, there
are other editors that can improve on your work. At the moment, I'd
just like to get a few tips out there! If I see a lot of wiki
submissions without much discussion in the thread, I'll probably post
links to the new tips or collect a list somewhere on the wiki.

Here are a couple of simple ideas. Some of these are probably not
worth a tip on their own, but perhaps may make a nice "quick tips"
list:
* Opening a diff window for a buffer that you are also editing in
another tab, without messing up window layout or options set by
:diffthis
* Opening a full-screen window on a buffer without messing up buffer
layout or messing with :mkview/:mksession
* Running a command on a limited selection of buffers without using
the argument list (see
http://vim.wikia.com/wiki/User:Fritzophrenic/Repeat_a_command_on_a_selection_of_buffers
for some notes on this and a potentially acceptable tip stub)

If you don't like the idea of using tab pages, this is not the thread
to say so. We all know that Vim tabs don't act like the tabs in other
editors. I'm starting this thread to find some good reasons why this
is so. Criticism of specific ideas or a brief discussion of
alternative methods is fine.

Let's get the ideas flowing!

Ben Fritz (fritzophrenic)

Bill Odom

unread,
Nov 28, 2009, 6:33:14 AM11/28/09
to vim-l, vim_use
On Thu, Nov 26, 2009 at 12:16 AM, Benjamin Fritz
<fritzo...@gmail.com> wrote:
>
> I'm sure there are clever ideas out there that leverage the power of
> tab pages in Vim, that are difficult or impossible to accomplish
> otherwise.

I mostly use tab pages for things I want close at hand, but out of the
way. Some examples off the top of my head:

* Multiple full-page Vim help topics, each in their own
conveniently-labeled tab page.

* Reference material (API docs, framework source code, project notes,
etc.) that I need to refer to often, but don't necessarily want taking
up screen real estate adjacent to whatever I'm working on.

* At-a-glance summaries: I sometimes work in a buffer with most or all
folds open, and keep a second tab page buffer with all folds closed.
The folded version serves as an overview of the entire file, usually
visible on a single screen.

* Quick Vim environment modifications: I'm always tweaking my Vim
settings, but I don't want to disrupt whatever I'm (supposed to be)
working on just to update my .vimrc. I have a key map that opens
$MYVIMRC and $MYGVIMRC in new tabs, so I can jump in and make whatever
changes are necessary, then close them and immediately go back to what
I was doing.

* "X-ray" buffers: I'll sometimes keep an alternate representation of
a buffer in a separate tab page, with useful but visually-noisy
options like 'list', 'cursorcolumn', 'cursorline', and 'number' all
turned on, several :match patterns active, etc. This way, I can keep
my regular working view clean and uncluttered, but quickly flip over
to the information-overload version (the "x-ray") when I need it. (You
don't have to get this crazy with it, of course; the idea works for
pretty much any setting in `:help option-summary` labeled 'local to
window'.)

* Scratchpads: Tab pages are good for throwaway buffers, where I work
with random chunks of text before (possibly) incorporating them into a
file I plan to keep around.

* Redirected Ex command output: I often want to use the output from an
Ex command (vs. just viewing it in the status area), so I have a
routine that runs a command, captures the output, then opens a new tab
page containing the captured text. As with most of these techniques,
this could also be done with a new window, or even within the current
window, but I find using a new tab page less disruptive.

* Mini-sessions: If you remove 'tabpages' from 'sessionoptions',
:mksession will only pay attention to the current tab page. This makes
it easy to use tab pages as a lightweight project-organization tool --
just open a set of files in whatever window layout you like, then run
`:mksession some-random-project.vim` to save the current tab page as a
session. To work on that set of files again, open a new tab page and
:source the appropriate session file.


I don't know if any of these rise to the level of full-blown tips, but
perhaps they'll spur discussion.

Thanks,
Bill

Benjamin Fritz

unread,
Nov 28, 2009, 11:29:34 AM11/28/09
to vi...@wikia.com, vim_use
Wow, Bill. You have some great ideas, and some of them I haven't
thought of before. Here are some of my thoughts on how they might be
included in the wiki:

On Sat, Nov 28, 2009 at 5:33 AM, Bill Odom <wno...@tmtowtdi.com> wrote:
> * Multiple full-page Vim help topics, each in their own
> conveniently-labeled tab page.
>
> * Reference material (API docs, framework source code, project notes,
> etc.) that I need to refer to often, but don't necessarily want taking
> up screen real estate adjacent to whatever I'm working on.
>

These both fall into the "full-page window that doesn't mess with your
window layout" category. I think they would both be great, briefly
mentioned in an "Intro to tap pages" tip.

> * At-a-glance summaries: I sometimes work in a buffer with most or all
> folds open, and keep a second tab page buffer with all folds closed.
> The folded version serves as an overview of the entire file, usually
> visible on a single screen.
>

This is a very interesting idea which I hadn't thought of and may use
myself. It could lead to other use cases; for example, rapidly finding
a place in a file, setting a mark (local to the buffer), and jumping
to it in another window/tab. I'm not sure where to put it. It seems a
little small for a tip by itself. It would probably be OK in the intro
to tab-pages tip, or perhaps a folding tip. It potentially could be
included with your "X-Ray tab" tip below.

> * Quick Vim environment modifications: I'm always tweaking my Vim
> settings, but I don't want to disrupt whatever I'm (supposed to be)
> working on just to update my .vimrc. I have a key map that opens
> $MYVIMRC and $MYGVIMRC in new tabs, so I can jump in and make whatever
> changes are necessary, then close them and immediately go back to what
> I was doing.
>

Another good "quick full-page window" tip, good for brief mention in
the intro tip.

> * "X-ray" buffers: I'll sometimes keep an alternate representation of
> a buffer in a separate tab page, with useful but visually-noisy
> options like 'list', 'cursorcolumn', 'cursorline', and 'number' all
> turned on, several :match patterns active, etc. This way, I can keep
> my regular working view clean and uncluttered, but quickly flip over
> to the information-overload version (the "x-ray") when I need it. (You
> don't have to get this crazy with it, of course; the idea works for
> pretty much any setting in `:help option-summary` labeled 'local to
> window'.)
>

I really like this one. The idea is very basic, but perhaps with some
expansion--some pre-made commands, etc.--it could make a tip on its
own. I think it deserves more than a short section in an "intro to
tabs" tip. Of course, it could be done in the same window with the
ability to restore the window-local settings, or a split window, so
these techniques should be mentioned as well. But I like that the tab
page doesn't take up additional screen real estate, and you don't need
to worry about restoring the state of the window when you're done.

> * Scratchpads: Tab pages are good for throwaway buffers, where I work
> with random chunks of text before (possibly) incorporating them into a
> file I plan to keep around.
>

I think this is another great "basic use" example for an intro tip.

> * Redirected Ex command output: I often want to use the output from an
> Ex command (vs. just viewing it in the status area), so I have a
> routine that runs a command, captures the output, then opens a new tab
> page containing the captured text. As with most of these techniques,
> this could also be done with a new window, or even within the current
> window, but I find using a new tab page less disruptive.
>

I thought we already had a tip on this, but I couldn't find it. John,
do you remember the tip? I actually do this myself from time to time
with a :tabnew | r !command. I, too, don't usually like to mess up my
screen layout with a buffer I'm just going to throw away shortly
anyway. At other times, the output of the command determines which
files I'm going to be opening next, and I like to be able to collect
all those files and the command output driving them in their own tab
page, like your "mini sessions" below.

> * Mini-sessions: If you remove 'tabpages' from 'sessionoptions',
> :mksession will only pay attention to the current tab page. This makes
> it easy to use tab pages as a lightweight project-organization tool --
> just open a set of files in whatever window layout you like, then run
> `:mksession some-random-project.vim` to save the current tab page as a
> session. To work on that set of files again, open a new tab page and
> :source the appropriate session file.
>

I also really like this very simple idea. Somehow I never thought of
this one either. I don't often use sessions currently, because it just
wasn't that useful for me. I often had a bunch of tabs open when I'm
just interested in restoring the state of one or two of them. I will
certainly use this one! I think this should go in its own section, in
a basic tip about using sessions. I'm not sure if we have one yet,
though, so for now it can be its own tip. Unless John knows of a good
generic "using sessions" tip.

Thanks for your contributions! I think we have the start to at least a
couple new tips. I look forward to seeing more!

John Beckett

unread,
Nov 28, 2009, 6:53:14 PM11/28/09
to vim...@googlegroups.com, vi...@wikia.com
Benjamin Fritz wrote:
>> * Redirected Ex command output: I often want to use the
>> output from an Ex command ...
>
> I thought we already had a tip on this, but I couldn't find
> it. John, do you remember the tip?

That's tip 95:
http://vim.wikia.com/wiki/Capture_ex_command_output

I have added a list of all the tips I can find relevant to
tab pages to tip 1347:
http://vim.wikia.com/wiki/Quick_tab_navigation_and_opening

Tip 1347 now has a section where we might plan what to do (which
tips to merge, what names to use, etc).

Where feasible, rather than add new tips I would prefer to
drastically modify (and probably rename) one of the existing
relevant tips; I'll think about that later.

I think there should a tip with an introduction to the fact that
tabs exist but are different from other editors. That page
should have an outline of the various ideas you and Bill have
discussed.

Another tip should have suggestions for tab navigation (this
might be combined with the introduction, but probably that would
be unduly complex).

John

Reply all
Reply to author
Forward
0 new messages