conditional map in normal mode?

左心房为你撑大大i 提交于 2019-12-24 00:46:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!