diff --git a/doc/vimagit.txt b/doc/vimagit.txt
index dd3c0c7930ce68f44cf8718a992de4b4dc17844f..e0ef71e178cc88c05e3c3ce3972a7c6307ad926c 100644
--- a/doc/vimagit.txt
+++ b/doc/vimagit.txt
@@ -475,6 +475,14 @@ This option automatically opens the fold of the hunk cursor has jump to.
 Default value is 1.
 let g:magit_auto_foldopen=[01]
 
+                                                     *vimagit-g:magit_scrolloff*
+Set *'scrolloff'* value in magit buffer.
+Minimal number of screen lines to keep above and below the cursor.
+Default value is 3.
+Set to -1 if you do not want to set scrolloff, 0 to disable scrolloff in magit
+buffer.
+let g:magit_scrolloff=3
+
                                               *vimagit-g:magit_default_sections*
 With this variable, the user is able to choose which sections are displayed in
 magit buffer, and in which order.
diff --git a/plugin/magit.vim b/plugin/magit.vim
index 8b6a9a4a491d3b4efff6cffd376f2f3f78105782..14553825d6c802f09a85d42bcf8e895a255b8f5b 100644
--- a/plugin/magit.vim
+++ b/plugin/magit.vim
@@ -37,6 +37,8 @@ let g:magit_refresh_gitgutter      = get(g:, 'magit_refresh_gitgutter',
 
 let g:magit_commit_title_limit     = get(g:, 'magit_commit_title_limit',        50)
 
+let g:magit_scrolloff              = get(g:, 'magit_scrolloff',                 3)
+
 let g:magit_warning_max_lines      = get(g:, 'magit_warning_max_lines',         10000)
 
 let g:magit_git_cmd                = get(g:, 'magit_git_cmd'          ,         "git")
@@ -808,6 +810,17 @@ function! magit#show_magit(display, ...)
 	setlocal nomodeline
 	let &l:foldlevel = b:magit_default_fold_level
 	setlocal filetype=magit
+	if ( g:magit_scrolloff != -1 )
+		if ( has("patch-8.1.0864") )
+			let &l:scrolloff = g:magit_scrolloff
+		else
+			let s:default_scrolloff=&scrolloff
+			" ugly hack, scrolloff is a global only option before patch 8.1.0864
+			execute "autocmd BufLeave " . buffer_name . " :set scrolloff=" . s:default_scrolloff
+			execute "autocmd BufEnter " . buffer_name . " :set scrolloff=" . g:magit_scrolloff
+			let &scrolloff = g:magit_scrolloff
+		endif
+	endif
 
 	augroup vimagit_buffer
 	autocmd!