I would like to use CTRLH for two different commands, depending on the context.

If there is a split left to the currently focused split, focus it:

nnoremap <c-h> <C-w>h

Otherwise, focus the previous tab:

nnoremap <c-h> gT<cr>

How can I express this condition in my ~/.vimrc?

1 Answer 1


One way is to check window number with winnr(). If number didn't changed, there's nothing to the left any more and previous tab will be selected.

function! LeftOrPrevTab()
  let win_no = winnr()
  wincmd h
  if win_no == winnr()
    normal gT

nnoremap <C-h> :call LeftOrPrevTab()<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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