10

我正在编写一个用于以特殊方式注释代码的插件,并且在可视模式或正常模式下调用时它的行为应该有所不同。

是否有函数或某种方法可以确定调用函数时用户所处的模式?

4

1 回答 1

7

There's

mode([expr]) Return a string that indicates the current mode.

http://vimdoc.sourceforge.net/htmldoc/eval.html#mode%28%29

but that might not work since you're probably going to start command mode in the rhs of the mapping.

A more robust way would be to set up slightly different mappings like

nmap <Leader>c :call MyFunc('n')<CR>
vmap <Leader>c :call MyFunc('v')<CR>

and use the argument value to know what mode the user was in.

于 2012-05-30T21:46:20.123 回答