Tip 1624 Printable Monobook Previous Next

created 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

:$-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'


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


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)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.