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.