From 6cd62ea441bd1aefd0dd4f532399b54be1592211 Mon Sep 17 00:00:00 2001 From: Jerome Reybert <jreybert@gmail.com> Date: Sat, 21 May 2022 22:23:12 +0200 Subject: [PATCH] Fix jump_to function when jumping to a dirty existing buffer jump_to opens the `filename` with `:edit`, no matter is the buffer is already opened in vim. It fails if the buffer already exists and if it has unsaved modifications. Simply check if the buffer exists, and if so, open it with `:buffer`, otherwise `:edit` it like a new file. fixes #194 --- plugin/magit.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index b201519..55bc4ed 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -1314,7 +1314,11 @@ function! magit#jump_to() endif try - execute "edit " . "+" . line_in_file . " " filename + if ( bufexists(filename) ) + execute "buffer " . "+" . line_in_file . " " filename + else + execute "edit " . "+" . line_in_file . " " filename + endif catch if ( v:exception == 'Vim:Interrupt' && buf_win == 0) close -- GitLab