条件图在正常模式下? [英] conditional map in normal mode?

查看:121
本文介绍了条件图在正常模式下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在正常模式下,是否可以在vim中执行条件映射?
我已经看到它用于插入模式。
我想重新映射gq,具体取决于函数的结果。
如下所示:

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

请注意, g:set_formatprg()不会总是有相同的值,所以不能替换为

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


推荐答案

表达式地图使其变得简单

An expression map makes it easy

nnoremap <expr> gq g:set_formatprg() ? 'gq' : '='

有关更多帮助,请参阅

:h map-expression

这篇关于条件图在正常模式下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆