We can open a file in gVim at line 99:

$ gvim file +99 &

With the same file open in Emacs, I can open it in gVim:

(when (eq system-type 'gnu/linux)
    (global-set-key (kbd "C-c g") (lambda ()
        (call-process "gvim" nil 0 nil buffer-file-name)
        (message "opened in gVim"))))

We can get the line number at point:

(string-to-number (format-mode-line "%l"))

I can't figure how to add that line number into my Emacs call to gVim such that the latter opens at the same line number. I suppose it's something like this:

(call-process "gvim" nil 0 nil (buffer-file-name +(string-to-number (format-mode-line "%l"))))

Any ideas how to correctly add in that line number?

1 Answer 1


Use the format function to construct a string from pieces. Also, use line-number-at-pos to get the current line numbers, which lets you get the correct number even if the buffer is narrowed.

(call-process "gvim" nil 0 nil
              (format "+%d" (line-number-at-pos nil t)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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