diff --git a/plugin/magit.vim b/plugin/magit.vim
index 2e1adcc1de12badb7384094738b0199d5e947643..d1c518009652b139d049150a29984d33a375b1c4 100644
--- a/plugin/magit.vim
+++ b/plugin/magit.vim
@@ -791,6 +791,17 @@ function! magit#show_magit(display, ...)
 
 	call magit#update_buffer()
 
+	function! s:jump_first_file()
+		let unstaged_files = b:state.get_files_ordered('unstaged')
+		if ( !empty(unstaged_files) )
+			call cursor(unstaged_files[0].line_pos, 0)
+		else
+			let staged_files = b:state.get_files_ordered('staged')
+			if ( !empty(staged_files) )
+				call cursor(staged_files[0].line_pos, 0)
+			endif
+		endif
+	endfunction
 	" move cursor to (in priority order if not found):
 	"  - current file unstaged
 	"  - current file staged
@@ -807,17 +818,11 @@ function! magit#show_magit(display, ...)
 				let file = b:state.get_file('staged', cur_file, 0)
 				call cursor(file.line_pos, 0)
 			catch 'file_doesnt_exists'
-				let unstaged_files = b:state.get_files_ordered('unstaged')
-				if ( !empty(unstaged_files) )
-					call cursor(unstaged_files[0].line_pos, 0)
-				else
-					let staged_files = b:state.get_files_ordered('staged')
-					if ( !empty(staged_files) )
-						call cursor(staged_files[0].line_pos, 0)
-					endif
-				endif
+				call s:jump_first_file()
 			endtry
 		endtry
+	else
+		call s:jump_first_file()
 	endif
 
 endfunction