I know that I can do a conditional key mapping by map-expression
:
map [key] [condition] ? [foo] : [bar]
But now my situation is somehow awkward. I want to map <C-h>
to <C-w>h
if I have more than one windows in my VIM, and map it to :bprev
if there is only one window in my VIM.
I've tried with
nnoremap <C-h> winnr('$')>1 ? '<C-w>h' : ':bprev<CR>'
But it doesn't work as .vimrc
is only read once when I start VIM. So I also tried with autocmd
and failed. Could anyone help me?