Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to detect whether or not I am in the right most (or left, top, bottommost) split. In other words, when ctrl-w h would do nothing. Is there a way to do that?

share|improve this question
up vote 4 down vote accepted

There's only winnr(), which is a sequential numbering; i.e. you can only check for topleft- and bottomright-most window, but not the exact window relations. If you need this information in a mapping / script, you'd have to do exactly as you've described:

function! IsLeftMostWindow()
    let curNr = winnr()
    wincmd h
    if winnr() == curNr
        return 1
    wincmd p " Move back.
    return 0

EDIT: winnr('$') is a special case which returns the highest index in the current tab. So if winnr() == winnr('$'), you're on the leftmost (or the only) window.

share|improve this answer

If you are using split screens in vim, you will see in the bottom of all of the split screens a bar with the filename (and information about the position of the cursor). In the active window, the text in this bar bold-face. So by checking the bold-face text, you can immediately see which of the splits you activated.

share|improve this answer
I hope this is enough information, or is there a reason to have automatized detection? – Bernhard Feb 22 '13 at 7:24
I was referring to from vimscript, I know how to tell which pane I'm in with my eyes :) – Aaron Jensen Feb 23 '13 at 4:40
@AaronJensen I couldn't tell from your question, but you got a perfect answer anyhow :) – Bernhard Feb 23 '13 at 9:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.