I had the following mapping to go to the 1st non blank character of a line
nnoremap M ^
I then decided that if I was already at the 1st non blank character I wanted M to take me to the absolute 1st character of the line.
I was able to hack together the following vimscript function to do this.
func Mbehaviour() let origPos = getcurpos() normal! ^ let newPos = getcurpos() call setpos('.', origPos) if newPos == origPos execute "normal! \<Home>" else normal! ^ endif endfun
& then map this to M with
nnoremap M :call Mbehaviour()<CR>
My question is how can I get the same thing to work in visual mode?