I have previously asked this in StackOverflow (May 2015), but without getting any replies that I was completely happy with.
This ought to be simple: I want to configure Vim to set number
whenever the editor is in Ex mode (to get visible line numbers), but never have that option set in visual mode. How?
If the solution involves having to start ex
instead of vim
, that's fine, but the solution should ideally also cover the case of entering Ex mode from visual mode (using Q in Vim visual mode, for example), and the case where I switch back to visual mode (using :vi
in Ex mode).
The closest I've come is the following suggestion (which I would be happy if someone could explain to me, because I don't fully understand it):
let &number = mode(1) ==# 'ce'
nnoremap <silent> Q :set number<CR>Q
This works for turning number
on when entering Ex mode, but will leave it activated upon entering Vim visual mode again.
A solution that also works in nvi
would be nice, but not necessary.
VisualEnter
andVisualLeave
events as we haveInsertEnter
andInsertLeave
events. At best you could override the key sequences that change the current mode. But there will always be uncaught mode changes. If that's really that important, open an RFC-issue on vim github to ask for such events (You may also wantNormalEnter
andLeave
and so on). Then, writing what you're looking for will be a piece of cake.