When I execute a function in vim, it puts my cursor back on the line at column 1. Is there a way to get back to where my cursor previously was on that line, i.e., the exact column number?

I thought perhaps doing:


Would get me back to the exact cursor position, but that seems to take me to the line before (and not the position of the existing line before it was moved). Is this possible to do? Here would be an example of what I was trying also from within the function:

func MyFunction()
    call cursor(line('.'), col('.'))
  • 1
    "existing line before it was moved" Can you give us a more concrete example of how your function is moving the lines around? It's hard to answer this question without knowing more about what you're currently doing...
    – filbranden
    Jun 13, 2020 at 9:33
  • Double backtick takes back to the position of an automatic bookmark. Depending on the movement command that bookmark may or may not be updated (e.g. cursor() doesn't alter it).
    – Matt
    Jun 13, 2020 at 9:57
  • 2
    One can manually place marks (in a function or elsewhere)
    – D. Ben Knoble
    Jun 13, 2020 at 12:51

1 Answer 1


You can create a mark, say c, at current cursor position using mc, execute your function, and then come back to that exact position using `c. You can include it around your maps/remaps/functions as it can be rather cumbersome to type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.