How to write conditional mapping in VIM?

I want to do nnoremap Q :q!<cr>and nnnoremap Q :bd<CR>how can I mix these two bindings?
Ideally, I want to make the binding Qsmart enough to know when we are in the buffer, and when is the last buffer in the window.

+4
source share
1 answer

map <expr>( :h map-<expr>) is your friend.

nnoremap <expr> Q yourConditionExpression ? ':q!<cr>':':bd<cr>'

In the above

yourConditionExpression

may be a boolean expression, for example. 3>0or the function returns boolean. You can put control logic there.

+7
source

Source: https://habr.com/ru/post/1668730/


All Articles