I have a vimscript function that needs to call Python code, depending on what mode I'm in. Some posts here recommend to use :mode()
such as Within a function, Is there a way to determine if vim is in insert mode? and How to get the current mode in vim?
The problem that I'm having is that mode()
doesn't work as expected for me.
For example, if you do this ...
function Test()
echo mode()
endfunction
vnoremap <leader>v :call Test()<CR>
and then go into visual mode or visual block mode or visual line mode (v
, <ctrl-v>
, V
) and run <leader>v
, this function prints "n" for all three.
What I wanted to do was to, in python, call
vim.command('let l:mode = mode()')
mode = vim.eval('l:mode')
and then use the mode
variable for my script but because it always seems to return "n", this hasn't worked.
Any advice is appreciated