I want to write a function which allows me to execute different movement commands using the same key pressed repeatedly. So, I wrote a function Jumptails
and mapped it to the key <End>
. The first time I press <End>
it jumps to the end of line ($
), next to the end of the visible window (L
) and finally to the end of file (G
). If another key is being pressed, the move list shall be reset so that the next time I press <End>
it starts from scratch using $
.
For this to work I need to know from inside that function if the function has been executed before. I tried to use the colon register @:
, but it does not seem to contain the last executed function, only the last executed "interactive" :ex command.
Is there some way to achieve something like this?
Here's the code I came up with so far:
let w:lastpos = []
func Jumptails()
let l:lastcmd = @:
echom "lastcmd: " @:
if l:lastcmd =~ 'Jumptails' " <= doesn't work and is always false
echom "inside"
else
let w:lastpos = ['G', 'L', '$']
endif
" extract next command and cycle command list
let l:max = len(w:lastpos) - 1
let l:current = w:lastpos[l:max]
call remove(w:lastpos, l:max)
call insert(w:lastpos, l:current)
execute "normal! " . l:current
endfunc
nnoremap ^[[e~ :call Jumptails()<Cr>