Vim Tips Wiki
m (→‎Comments: Rolodex: not sure it was me)
(Assign tip id + convert to TipNew template + minor clean)
Line 1: Line 1:
  +
{{TipNew
{{TipProposed
 
|id=0
+
|id=1624
|previous=0
+
|previous=1623
|next=0
+
|next=1625
 
|created=May 4, 2009
 
|created=May 4, 2009
 
|complexity=basic
 
|complexity=basic

Revision as of 08:34, 22 September 2009

Tip 1624 Printable Monobook Previous Next

created May 4, 2009 · complexity basic · author Tonymec · version 7.0


It's obvious once you're shown it, so here are a few examples (to go to the second-last window):

This does not work
$-1^Ww

:$-1wincmd w

The former will act on the dollar sign without using it as a count; the latter counts $ as the number of lines in the current buffer, and goes to the very last window if the "$-1" count exceeds the number of windows in the current or only tab page.

This works

:exe winnr('$') - 1 'wincmd w'

References

:help CTRL-W_w
:help :wincmd
:help :execute
:help winnr()

Comments

I'd like to see a use case for this, that merits its becoming a proper tip. It's a good observation, though. (Spiiph 23:55, 28 July 2009 (UTC))

If you have no more than a handful of split-windows, you don't need this tip because you can tell at a glance the number of the wanted window (unless, of course, you want to go to the nth-from-last window from a mapping or a script). But if you have a lot of windows (in my current gvim session there are 21, opened "Rolodex style" with :set wh=9999 wmh=0), you'd need a better counting-at-a-glance ability than most people have, even to be able to type the right number at the keyboard. But we can, for instance, create the following to always go to the second-last window by hitting F12:
	:map	<F12>	:exe winnr('$') - 1 'wincmd w'<CR>
--Tonymec 02:55, 5 August 2009 (UTC)

Tony: I do not think you have mentioned your "Rolodex style" window layout on the wiki (although I've seen you refer to it at vim_use). Would you be able to add a couple of paragraphs to this tip because it's an interesting idea and it would be a good illustration of the point of the tip? Or if you prefer, reply with a description and I'll incorporate it. BTW it is mentioned in the last comment at Window zooming convenience. JohnBeckett 07:30, 5 August 2009 (UTC)

I'm not sure I've made a tip for it, though I have indeed mentioned it time and again on the vim groups, even on vim@ since before 7.0 came around. I called it "the poor man's tabs" at first, though "Rolodex" is more descriptive, once someone figuratively threw the latter name on the wall, it stuck. The idea is obvious once you have seen it:

:set noequalalways winminheight=0 winheight=9999 helpheight=9999
  • 'noequalalways' makes sure Vim doesn't try to make all windows equal.
  • 'winminheight' set to 0 means non-current windows may collapse to a status line and nothing else (thus sparing screen real estate)
  • 'winheight' at 9999 swells the current window to maximum height, squashing all non-current windows
  • 'helpheight' does the same when in a help window.

The result is that the current window opens full-height, pushing all other windows above and below it to just a status line each. To see what it means, figure a Rolodex phone directory, like we (or our fathers' secretaries) used to have before personal computers came around. The current card is open full-size, with the borders of the previous cards visible above it and those of the following cards below it. You can even push the similarity further: mouse-clicking any status line opens that "Rolodex page" in Vim, like holding one index letter on the top or bottom side of the Rolodex® allowed to open that directory card in the good old paper-and-ink times of a generation ago. Of course the "Vim Rolodex pages" can also be turned up and down one-by-one with ^Ww and ^WW etc.

See:

--Tonymec 21:49, 5 August 2009 (UTC)