问题
Is it possible in vim to do a conditional map, in normal mode? I've seen it for insert mode. I want to remap gq, depending on the outcome of a function. Something like:
nnoremap gq if(g:set_formatprg()) | gq | else | = | endif
Notice that g:set_formatprg() will not always have the same value, so it cannot be replaced by
if(!g:set_formatprg()) | nnoremap gq = | endif
回答1:
An expression map makes it easy
nnoremap <expr> gq g:set_formatprg() ? 'gq' : '='
For more help see
:h map-expression
来源:https://stackoverflow.com/questions/15440985/conditional-map-in-normal-mode