Vim: how to get the mode I'm currently in
vim
Solution
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.
Problem
I'm writing a plugin for commenting the code in special way and it should act a bit different when called in visual or normal modes. Is there a function or some way to determine the mode in which the user is (was) when the function was called?