My vim plugin has a command to jump to a different location (just like tags).
I use the cursor
function for that.
How do I record the previous location in the jumplist, so that Ctrl+O works as expected?
My vim plugin has a command to jump to a different location (just like tags).
I use the cursor
function for that.
How do I record the previous location in the jumplist, so that Ctrl+O works as expected?
I myself also wanted to this, and what works for me was mark ` before cursor move.
normal! m`
call cursor(l, c)
As help indicate, both setpos() and cursor() don't modify jumplist, so what's the difference of setpos() and cursor(), strange!
:help cursor()
can't be clearer:
[…]
Does not change the jumplist.
[…]
(EDIT)
This means that cursor()
jumps are not recorded in the jumplist and therefore, that cursor()
is an inappropriate tool, here.
(ENDEDIT)
As an alternative, you could use something like
execute "normal " . target_line . "G" . target_col . "|"
which is perfectly compatible with <C-o>
and <C-i>
and just as idiomatic as
call cursor(target_line,target_col)
even if it gives the chills to JavaScripters ;-)
Simply mark that position before moving your cursor by setting the ' mark. This could be done by either using the normal mode m
command, or even a call to setpos()
, e.g. call setpos("''", getpos("."))
would add the current cursor position to the jump list.