Vim: how to get the mode I'm in now

I am writing a plugin for commenting code in a special way, and it should act a little differently when called in visual or normal modes.

Is there a function or some way to determine the mode in which the user was (was) when the function was called?

+7
source share
1 answer

There

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

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

but this may not work, since you are probably going to run command mode in rhs display.

A more reliable way would be to establish slightly different mappings, such as

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

and use the value of the argument to find out what mode the user was in.

+6
source

All Articles