diff --git a/README.md b/README.md
index d874065f1f536dd86f05f2fc4dc1568fb03aba41..8d7a1df2ceea8de5d395a05b8f62a406ecdf0653 100644
--- a/README.md
+++ b/README.md
@@ -196,16 +196,75 @@ Open Magit buffer
 
 Following mappings are set locally, for magit buffer only, in normal mode.
 
-##### Enter,\<CR\>
+Some mappings are set for the whole magit buffer, others are set for specific section only.
+
+##### Whole buffer mappings
+
+-----------------------------------
+
+<kbd>CC</kbd>, <kbd>:w</kbd> <kbd>:x</kbd> <kbd>:wq</kbd> <kbd>ZZ</kbd>
+
+ * From [stage mode](stage_mode), set [commit mode](commit_mode) in [normal flavor](commit_mode_flavors) and show empty "Commit message" section.
+
+<kbd>CA</kbd>
+
+ * From [stage mode](stage_mode) or [commit mode](commit_mode): set [commit mode](commit_mode) in [amend flavor](commit_mode_flavors), and display "Commit message" section with previous commit message. Commit will be meld with previous commit.
+
+<kbd>CF</kbd>
+
+ * From [stage mode](stage_mode): amend the staged changes into the previous commit, without modifying previous commit message.
+
+-----------------------------------
+
+<kbd>Ctrl</kbd>+<kbd>n</kbd>,<kbd>Ctrl</kbd>+<kbd>p</kbd>
+
+ * Move to **N**ext or **P**revious hunk.
+
+-----------------------------------
+
+<kbd>Enter</kbd>
  * All files are folded by default. To see the changes in a file, move cursor to the filename line, and press Enter. You can close the changes display retyping Enter.
 
-##### zo,zO
- * Typing zo on a file will unhide its diffs.
+<kbd>zo</kbd>,<kbd>zO</kbd>
+
+ * Typing <kbd>zo</kbd> on a file will unhide its diffs.
+
+<kbd>zc</kbd>,<kbd>zC</kbd>
 
-##### zc,zC
  * Typing zc on a file will hide its diffs.
 
-##### S
+-----------------------------------
+
+<kbd>R</kbd>
+
+ * Refresh magit buffer
+
+-----------------------------------
+
+<kbd>-</kbd> , <kbd>+</kbd> , <kbd>0</kbd>
+
+ * Shrink,enlarge,reset diff context
+
+-----------------------------------
+
+<kbd>q</kbd>
+
+ * Close the magit buffer
+
+-----------------------------------
+
+<kbd>?</kbd>
+
+ * Toggle help showing in magit buffer
+
+-----------------------------------
+
+##### Stage / unstage sections mappings
+
+-----------------------------------
+
+<kbd>S</kbd>
+
  * If cursor is in a hunk, stage/unstage hunk at cursor position.
  * If cursor is in diff header, stage/unstage whole file at cursor position.
  * If some lines in the hunk are selected (using **v**), stage only visual selected lines (only works for staging).
@@ -213,25 +272,45 @@ Following mappings are set locally, for magit buffer only, in normal mode.
  * When cursor is in "Unstaged changes" section, it will stage the hunk/file.
  * On the other side, when cursor is in "Staged changes" section, it will unstage hunk/file.
 
-##### F
+-----------------------------------
+
+<kbd>F</kbd>
+
  * Stage/unstage the whole file at cursor position.
  * When cursor is in "Unstaged changes" section, it will stage the file.
  * On the other side, when cursor is in "Staged changes" section, it will unstage file.
 
-##### L
+-----------------------------------
+
+<kbd>L</kbd>
+
  * Stage the line under the cursor.
 
-##### M
+-----------------------------------
+
+<kbd>M</kbd>
+
  * Mark the line under the cursor "to be staged".
  * If some lines in the hunk are selected (using **v**), mark selected lines "to be staged".
  * To staged marked lines in a hunk, move cursor to this hunk and press **S**.
 
-##### DDD
+-----------------------------------
+
+<kbd>DDD</kbd>
  * If cursor is in a hunk, discard hunk at cursor position.
  * If cursor is in diff header, discard whole file at cursor position.
  * Only works in "Unstaged changes" section.
 
-##### E
+-----------------------------------
+
+<kbd>I</kbd>
+
+ * Add the file under the cursor in .gitignore
+
+-----------------------------------
+
+<kbd>E</kbd>
+
 If cursor is in a hunk, cursor will move in the file containing this hunk, at
  the line of the beginning of the hunk.
  * if the file is already visible in a window, cursor moves to this window at
@@ -245,39 +324,26 @@ E means 'edit'.
 
 :exclamation: this function is extremely powerful, just give it a try!
 
-##### \<C-n>,\<C-p>
- * Move to **N**ext or **P**revious hunk.
+-----------------------------------
 
-##### CC
- * From [stage mode](stage_mode), set [commit mode](commit_mode) in [normal flavor](commit_mode_flavors) and show empty "Commit message" section.
- * From [commit mode](commit_mode), commit all staged changes with [commit flavor](commit_mode_flavors) (*normal* or *amend*) with message in "Commit message" section.
+##### Commit section mappings
 
-##### :w :x :wq ZZ
- * From [commit mode](commit_mode), commit all staged changes with [commit flavor](commit_mode_flavors) (*normal* or *amend*) with message in "Commit message" section.
+-----------------------------------
 
-##### CA
- * From [stage mode](stage_mode) or [commit mode](commit_mode): set [commit mode](commit_mode) in [amend flavor](commit_mode_flavors), and display "Commit message" section with previous commit message. Commit will be meld with previous commit.
+<kbd>CC</kbd>, <kbd>:w</kbd> <kbd>:x</kbd> <kbd>:wq</kbd> <kbd>ZZ</kbd>
 
-##### CF
- * From [stage mode](stage_mode): amend the staged changes into the previous commit, without modifying previous commit message.
+ * From [commit mode](commit_mode), commit all staged changes with [commit flavor](commit_mode_flavors) (*normal* or *amend*) with message in "Commit message" section.
 
-##### CU
- * From [commit mode](commit_mode): go back to stage mode (current commit message will be lost).
+<kbd>CA</kbd>
 
-##### I
- * Add the file under the cursor in .gitignore
+ * From [stage mode](stage_mode) or [commit mode](commit_mode): set [commit mode](commit_mode) in [amend flavor](commit_mode_flavors), and display "Commit message" section with previous commit message. Commit will be meld with previous commit.
 
-##### R
- * Refresh magit buffer
 
-##### -,+,0
- * Shrink,enlarge,reset diff context
+<kbd>CU</kbd>
 
-##### q
- * Close the magit buffer
+ * From [commit mode](commit_mode): go back to stage mode (current commit message will be lost).
 
-##### ?
- * Toggle help showing in magit buffer
+-----------------------------------
 
 #### Mapping update
 
diff --git a/autoload/magit/helper.vim b/autoload/magit/helper.vim
new file mode 100644
index 0000000000000000000000000000000000000000..dbb5cff53847f6a22880acf5460c3d0e8c30004a
--- /dev/null
+++ b/autoload/magit/helper.vim
@@ -0,0 +1,29 @@
+
+" magit#helper#get_filename: helper function to get the current filename, according to
+" cursor position
+" return: filename
+function! magit#helper#get_filename()
+	return substitute(getline(search(g:magit_file_re, "cbnW")), g:magit_file_re, '\2', '')
+endfunction
+
+" magit#helper#get_hunkheader: helper function to get the current hunk header,
+" according to cursor position
+" return: hunk header
+function! magit#helper#get_hunkheader()
+	return getline(search(g:magit_hunk_re, "cbnW"))
+endfunction
+
+" magit#utils#get_section: helper function to get the current section, according to
+" cursor position
+" return: section id, empty string if no section found
+function! magit#helper#get_section()
+	let section_line=getline(search(g:magit_section_re, "bnW"))
+	for [section_name, section_str] in items(g:magit_sections)
+		if ( section_line == section_str )
+			return section_name
+		endif
+	endfor
+	return ''
+endfunction
+
+
diff --git a/autoload/magit/mapping.vim b/autoload/magit/mapping.vim
index 20be253788b06c2b56754c2335bf33f362d66479..6bffbf8399c7dd513d36aed37a4f5cc1f8d13723 100644
--- a/autoload/magit/mapping.vim
+++ b/autoload/magit/mapping.vim
@@ -27,42 +27,146 @@ let g:magit_folding_toggle_mapping = get(g:, 'magit_folding_toggle_mapping',
 let g:magit_folding_open_mapping   = get(g:, 'magit_folding_open_mapping',      [ 'zo', 'zO' ])
 let g:magit_folding_close_mapping  = get(g:, 'magit_folding_close_mapping',     [ 'zc', 'zC' ])
 
+" magit#open_close_folding_wrapper: wrapper function to
+" magit#open_close_folding. If line under cursor is not a cursor, execute
+" normal behavior
+" param[in] mapping: which has been set
+" param[in] visible : boolean, force visible value. If not set, toggle
+" visibility
+function! s:mg_open_close_folding_wrapper(mapping, ...)
+	if ( getline(".") =~ g:magit_file_re )
+		return call('magit#open_close_folding', a:000)
+	elseif ( foldlevel(line(".")) == 2 )
+		if ( foldclosed(line('.')) == -1 )
+			foldclose
+		else
+			foldopen
+		endif
+	else
+		silent! execute "silent! normal! " . a:mapping
+	endif
+endfunction
+
+" s:nmapping_wrapper: wrapper for normal mapping commands
+" it needs a wrapper because some mappings must only be enabled in some
+" sections. For example, wa want that 'S' mapping to be enabled in staged and
+" unstaged sections, but not in commit section.
+" param[in] mapping the key for the mapping (lhs)
+" param[in] function the function to call (rhs)
+" param[in] ... : optional, section, the regex of the sections where to enable the
+" mapping. If there is no section parameter or if the section parameter regex
+" match the current section, the rhs is called. Otherwise, the mapping is
+" applied to its original meaning.
+function! s:nmapping_wrapper(mapping, function, ...)
+	if ( a:0 == 0 || magit#helper#get_section() =~ a:1 )
+		execute "call " . a:function
+	else
+		" feedkeys(..., 'n') is prefered over execute normal!
+		" normal! does not enter in insert mode
+		call feedkeys(a:mapping, 'n')
+	endif
+endfunction
+
+" s:xmapping_wrapper: wrapper for visual mapping commands
+" it needs a wrapper because some mappings must only be enabled in some
+" sections. For example, wa want that 'S' mapping to be enabled in staged and
+" unstaged sections, but not in commit section.
+" param[in] mapping the key for the mapping (lhs)
+" param[in] function the function to call (rhs)
+" param[in] ... : optional, section, the regex of the sections where to enable the
+" mapping. If there is no section parameter or if the section parameter regex
+" match the current section, the rhs is called. Otherwise, the mapping is
+" applied to its original meaning.
+function! s:xmapping_wrapper(mapping, function, ...) range
+	if ( a:0 == 0 || magit#helper#get_section() =~ a:1 )
+		execute a:firstline . "," . a:lastline . "call " . a:function
+	else
+		" feedkeys(..., 'n') is prefered over execute normal!
+		" normal! does not enter in insert mode
+		call feedkeys(a:mapping, 'n')
+	endif
+endfunction
+" s:mg_set_mapping: helper function to setup the mapping
+" param[in] mode the mapping mode, one letter. Can be 'n', 'x', 'i', ...
+" param[in] mapping the key for the mapping (lhs)
+" param[in] function the function to call (rhs)
+" param[in] ... : optional, section, the regex of the section(s)
+function! s:mg_set_mapping(mode, mapping, function, ...)
+	if ( a:0 == 1 )
+		execute a:mode . "noremap <buffer><silent><nowait> "
+					\ . a:mapping .
+					\ " :call <SID>" . a:mode . "mapping_wrapper(\"" .
+					\ a:mapping . "\", \"" .
+					\ a:function . "\"" .
+					\ ", \'" . a:1 . "\'" .
+					\ ")<cr>"
+	else
+		execute a:mode . "noremap <buffer><silent><nowait> "
+					\ . a:mapping .
+					\ " :call  " .
+					\ a:function . "<cr>"
+	endif
+endfunction
+
 function! magit#mapping#set_default()
 
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_stage_file_mapping .   " :call magit#stage_file()<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_stage_hunk_mapping .   " :call magit#stage_hunk(0)<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_discard_hunk_mapping . " :call magit#stage_hunk(1)<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_reload_mapping .       " :call magit#update_buffer()<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_edit_mapping .         " :call magit#jump_to()<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_commit_mapping .       " :call magit#commit_command('CC')<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_commit_amend_mapping . " :call magit#commit_command('CA')<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_commit_fixup_mapping . " :call magit#commit_command('CF')<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_close_commit_mapping . " :call magit#close_commit()<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_ignore_mapping .       " :call magit#ignore_file()<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_close_mapping .        " :call magit#close_magit()<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_diff_shrink .          " :call magit#update_diff('-')<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_diff_enlarge .         " :call magit#update_diff('+')<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_diff_reset .           " :call magit#update_diff('0')<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_toggle_help_mapping .  " :call magit#toggle_help()<cr>"
-
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_stage_line_mapping .   " :call magit#stage_vselect()<cr>"
-	execute "xnoremap <buffer><silent><nowait> " . g:magit_stage_hunk_mapping .   " :call magit#stage_vselect()<cr>"
-	
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_mark_line_mapping .    " :call magit#mark_vselect()<cr>"
-	execute "xnoremap <buffer><silent><nowait> " . g:magit_mark_line_mapping .    " :call magit#mark_vselect()<cr>"
-
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_jump_next_hunk .       " :call magit#jump_hunk('N')<cr>"
-	execute "nnoremap <buffer><silent><nowait> " . g:magit_jump_prev_hunk .       " :call magit#jump_hunk('P')<cr>"
+	call s:mg_set_mapping('n', g:magit_stage_hunk_mapping,
+				\"magit#stage_hunk(0)", '\<\%(un\)\?staged\>')
+	call s:mg_set_mapping('n', g:magit_stage_file_mapping,
+				\ "magit#stage_file()", '\<\%(un\)\?staged\>')
+	call s:mg_set_mapping('n', g:magit_discard_hunk_mapping,
+				\ "magit#stage_hunk(1)", '\<\%(un\)\?staged\>')
+	call s:mg_set_mapping('n', g:magit_stage_line_mapping,
+				\ "magit#stage_vselect()", '\<\%(un\)\?staged\>')
+	call s:mg_set_mapping('x', g:magit_stage_hunk_mapping,
+				\ "magit#stage_vselect()", '\<\%(un\)\?staged\>')
+	call s:mg_set_mapping('n', g:magit_mark_line_mapping,
+				\ "magit#mark_vselect()", '\<\%(un\)\?staged\>')
+	call s:mg_set_mapping('x', g:magit_mark_line_mapping,
+				\ "magit#mark_vselect()", '\<\%(un\)\?staged\>')
+
+	call s:mg_set_mapping('n', g:magit_ignore_mapping,
+				\ "magit#ignore_file()", '\<\%(un\)\?staged\>')
+	call s:mg_set_mapping('n', g:magit_edit_mapping,
+				\ "magit#jump_to()", '\<\%(un\)\?staged\>')
+
+	call s:mg_set_mapping('n', g:magit_reload_mapping,
+				\ "magit#update_buffer()")
+	call s:mg_set_mapping('n', g:magit_close_mapping,
+				\ "magit#close_magit()")
+	call s:mg_set_mapping('n', g:magit_diff_shrink,
+				\ "magit#update_diff('-')")
+	call s:mg_set_mapping('n', g:magit_diff_enlarge,
+				\ "magit#update_diff('+')")
+	call s:mg_set_mapping('n', g:magit_diff_reset,
+				\ "magit#update_diff('0')")
+	call s:mg_set_mapping('n', g:magit_toggle_help_mapping,
+				\ "magit#toggle_help()")
+
+	call s:mg_set_mapping('n', g:magit_commit_mapping,
+				\ "magit#commit_command('CC')")
+	call s:mg_set_mapping('n', g:magit_commit_amend_mapping,
+				\ "magit#commit_command('CA')")
+	call s:mg_set_mapping('n', g:magit_commit_fixup_mapping,
+				\ "magit#commit_command('CF')")
+	call s:mg_set_mapping('n', g:magit_close_commit_mapping,
+				\ "magit#close_commit()")
+
+	call s:mg_set_mapping('n', g:magit_jump_next_hunk,
+				\ "magit#jump_hunk('N')")
+	call s:mg_set_mapping('n', g:magit_jump_prev_hunk,
+				\ "magit#jump_hunk('P')")
+
 	for mapping in g:magit_folding_toggle_mapping
 		" trick to pass '<cr>' in a mapping command without being interpreted
 		let func_arg = ( mapping ==? "<cr>" ) ? '+' : mapping
-		execute "nnoremap <buffer><silent><nowait> " . mapping . " :call magit#open_close_folding_wrapper('" . func_arg . "')<return>"
+		execute "nnoremap <buffer><silent><nowait> " . mapping . " :call <SID>mg_open_close_folding_wrapper('" . func_arg . "')<return>"
 	endfor
 	for mapping in g:magit_folding_open_mapping
-		execute "nnoremap <buffer><silent><nowait> " . mapping . " :call magit#open_close_folding_wrapper('" . mapping . "', 1)<return>"
+		execute "nnoremap <buffer><silent><nowait> " . mapping . " :call <SID>mg_open_close_folding_wrapper('" . mapping . "', 1)<return>"
 	endfor
 	for mapping in g:magit_folding_close_mapping
-		execute "nnoremap <buffer><silent><nowait> " . mapping . " :call magit#open_close_folding_wrapper('" . mapping . "', 0)<return>"
+		execute "nnoremap <buffer><silent><nowait> " . mapping . " :call <SID>mg_open_close_folding_wrapper('" . mapping . "', 0)<return>"
 	endfor
 
 	" s:magit_inline_help: Dict containing inline help for each section
diff --git a/doc/vimagit.txt b/doc/vimagit.txt
index 055aaf5e15de88bceb322b1a20f515be5c28f120..636a56803595cbcf1f469973f0f087862f94caa2 100644
--- a/doc/vimagit.txt
+++ b/doc/vimagit.txt
@@ -189,26 +189,92 @@ Following mappings are broadly set, and are applied in all vim buffers.
 
 Local mappings
 --------------
+
 Following mappings are set locally, for magit buffer only, in normal mode.
 
-                                      *vimagit-<CR>*  *magit#open_close_folding()*
+Some mappings are set for the whole magit buffer, others are set for specific
+section only.
+
+
+--------    Whole buffer mappings                                     --------
+
+
+                                    *vimagit-CC*    *magit#commit_command('CC')*
+                                    *vimagit-g:magit_commit_mapping*
+  <CC>      From `stage mode`, set commit mode in `normal` flavor and show empty
+            "Commit message" section.
+
+                                    *vimagit-CA*    *magit#commit_command('CA')*
+                                    *vimagit-g:magit_commit_amend_mapping*
+  <CA>      From `stage mode` or `commit mode`: set commit mode in amend
+            flavor, and display "Commit message" section with previous commit
+            message.
+            Commit will be meld with previous commit.
+
+                                    *vimagit-CF*    *magit#commit_command('CF')*
+                                    *vimagit-g:magit_commit_fixup_mapping*
+  <CF>      From `stage mode`: amend the staged changes into the previous
+            commit, without modifying previous commit message.
+
+
+
+                                    *vimagit-<C-n>*          *magit#jump_hunk()*
+                                    *vimagit-<C-p>*
+                                    *vimagit-g:magit_jump_next_hunk*
+                                    *vimagit-g:magit_jump_prev_hunk*
+  <C-n>,<C-p>  Move to Next or Previous hunk.
+
+
+
+                                      *vimagit-<CR>* *magit#open_close_folding()*
                                       *vimagit-g:magit_folding_toggle_mapping*
-  <CR>      All file diffs are hidden by default. To see the changes in a
+  <Enter>   All file diffs are hidden by default. To see the changes in a
             file, move cursor to the filename line, and press Enter. You can
             close the changes display retyping Enter.
 
-                                      *vimagit-zo*   *magit#open_close_folding(1)*
+                                      *vimagit-zo* *magit#open_close_folding(1)*
                                       *vimagit-g:magit_folding_open_mapping*
-  zo,zO     Typing zo on a file will unhide its diffs.
+  <zo>,<zO> Typing zo on a file will unhide its diffs.
 
-                                      *vimagit-zc*   *magit#open_close_folding(0)*
+                                      *vimagit-zc* *magit#open_close_folding(0)*
                                       *vimagit-g:magit_folding_close_mapping*
-  zc,zC     Typing zc on a file will hide its diffs.
+  <zc>,<zC> Typing zc on a file will hide its diffs.
+
+
+
+                                    *vimagit-R*          *magit#update_buffer()*
+                                    *vimagit-g:magit_reload_mapping*
+  <R>       Refresh magit buffer.
+
+
+
+                                                           *magit#update_diff()*
+                                    *vimagit--* *vimagit-g:magit_diff_shrink*
+                                    *vimagit-+* *vimagit-g:magit_diff_enlarge*
+                                    *vimagit-0* *vimagit-g:magit_diff_reset*
+  -,+,0     Shrink,enlarge,reset diff context
+
+
+
+                                    *vimagit-q*
+                                    *vimagit-g:magit_close_mapping*
+  <q>       close magit buffer.
+
+
+
+                                    *vimagit-?*            *magit#toggle_help()*
+                                    *vimagit-g:magit_toggle_help_mapping*
+  <?>       Toggle help showing in magit buffer
 
-                                      *vimagit-S*            *magit#stage_hunk(0)*
-                                                           *magit#stage_vselect()*
+
+
+--------    Stage / unstage sections mappings                         --------
+
+
+                                      *vimagit-S*          *magit#stage_hunk(0)*
+                                                         *magit#stage_vselect()*
                                       *vimagit-g:magit_stage_hunk_mapping*
-  S         If cursor is in a hunk, stage/unstage hunk at cursor position.
+  <S>       If cursor is in a hunk, stage/unstage hunk at cursor position.
             If cursor is in diff header, stage/unstage whole file at cursor
             position.
             If some lines in the hunk are selected (see |visual-use|), stage
@@ -220,34 +286,47 @@ Following mappings are set locally, for magit buffer only, in normal mode.
             On the other side, when cursor is in "Staged changes" section, it
             will unstage hunk/file.
 
-                                      *vimagit-F*             *magit#stage_file()*
+
+
+                                      *vimagit-F*           *magit#stage_file()*
                                       *vimagit-g:magit_stage_file_mapping*
-  F         Stage/unstage the whole file at cursor position.
+  <F>       Stage/unstage the whole file at cursor position.
             When cursor is in "Unstaged changes" section, it will stage the
             file.
             On the other side, when cursor is in "Staged changes" section, it
             will unstage file.
 
+
+
                                       *vimagit-L*
-  L         Stage the line under the cursor (only works for staging)
+  <L>       Stage the line under the cursor (only works for staging)
+
+
 
                                       *vimagit-M*
-  M
-            Mark the current line to be staged.
+  <M>       Mark the current line to be staged.
             If some lines in the hunk are selected (see |visual-use|), mark
             selected lines.
             To staged marked lines, press S (see |vimagit-S|) in the current
             hunk.
 
+
                                     *vimagit-DDD*           magit#stage_hunk(1)*
                                     *vimagit-g:magit_discard_hunk_mapping*
-  DDD       If cursor is in a hunk, discard hunk at cursor position.
+  <DDD>     If cursor is in a hunk, discard hunk at cursor position.
             If cursor is in diff header, discard whole file at cursor
             position.
             Only works in "Unstaged changes" section.
 
+
+                                    *vimagit-I*            *magit#ignore_file()*
+                                    *vimagit-g:magit_ignore_mapping*
+  <I>       Add the file under the cursor in .gitignore
+
+
+
                                     *vimagit-E*                *magit#jump_to()*
-  E         If cursor is in a hunk, cursor will move in the file containing
+  <E>       If cursor is in a hunk, cursor will move in the file containing
             this hunk, at the line of the beginning of the hunk.
              - if the file is already visible in a |window|, cursor moves to
                this window at the hunk line
@@ -258,62 +337,35 @@ Following mappings are set locally, for magit buffer only, in normal mode.
             E means 'edit'.
             NOTE: this function is extremely powerful, just give it a try!
 
-                                    *vimagit-<C-n>*          *magit#jump_hunk()*
-                                    *vimagit-<C-p>*
-                                    *vimagit-g:magit_jump_next_hunk*
-                                    *vimagit-g:magit_jump_prev_hunk*
-  <C-n>,<C-p>  Move to Next or Previous hunk.
 
-                                    *vimagit-CC*    *magit#commit_command('CC')*
-                                    *vimagit-g:magit_commit_mapping*
-  CC        From `stage mode`, set commit mode in `normal` flavor and show empty
-            "Commit message" section.
-            From `commit mode`, commit all staged changes with commit flavor
-            (`normal` or `amend`) with message in "Commit message" section.
+--------    Commit section mappings                                   --------
+
 
-                                    *vimagit-:w*
+                                    *vimagit-CC *  *magit#commit_command('CC') *
+                                    *vimagit-:w *
+                                    *vimagit-g:magit_commit_mapping *
   :w :x :wq ZZ
+  <CC>      From `commit mode`, commit all staged changes with commit flavor
+            (`normal` or `amend`) with message in "Commit message" section.
+
             From `commit mode`, commit all staged changes with commit flavor
             (`normal` or `amend`) with message in "Commit message" section.
 
-                                    *vimagit-CA*    *magit#commit_command('CA')*
-                                    *vimagit-g:magit_commit_amend_mapping*
-  CA        From `stage mode` or `commit mode`: set commit mode in amend
+                                    *vimagit-CA *  *magit#commit_command('CA') *
+                                    *vimagit-g:magit_commit_amend_mapping *
+  <CA>      From `stage mode` or `commit mode`: set commit mode in amend
             flavor, and display "Commit message" section with previous commit
             message.
             Commit will be meld with previous commit.
 
-                                    *vimagit-CF*    *magit#commit_command('CF')*
-                                    *vimagit-g:magit_commit_fixup_mapping*
-  CF        From `stage mode`: amend the staged changes into the previous
-            commit, without modifying previous commit message.
-
-                                    *vimagit-CU*      *magit#close_commit()*
-                                    *vimagit-g:magit_close_commit_mapping*
-  CU        From `commit mode`: go back to stage mode (current commit message
+                                    *vimagit-CU *        *magit#close_commit() *
+                                    *vimagit-g:magit_close_commit_mapping *
+  <CU>      From `commit mode`: go back to stage mode (current commit message
             will be lost).
 
-                                    *vimagit-I*            *magit#ignore_file()*
-                                    *vimagit-g:magit_ignore_mapping*
-  I         Add the file under the cursor in .gitgnore
 
-                                    *vimagit-R*          *magit#update_buffer()*
-                                    *vimagit-g:magit_reload_mapping*
-  R         Refresh magit buffer.
-
-                                                           *magit#update_diff()*
-                                    *vimagit--* *vimagit-g:magit_diff_shrink*
-                                    *vimagit-+* *vimagit-g:magit_diff_enlarge*
-                                    *vimagit-0* *vimagit-g:magit_diff_reset*
-  -,+,0     Shrink,enlarge,reset diff context
-
-                                    *vimagit-q*
-                                    *vimagit-g:magit_close_mapping*
-  q         close magit buffer.
+------------------------------------------------------------------------------
 
-                                    *vimagit-?*            *magit#toggle_help()*
-                                    *vimagit-g:magit_toggle_help_mapping*
-  ?         Toggle help showing in magit buffer
 
 AUTOCMD                                                        *vimagit-autocmd*
 
diff --git a/plugin/magit.vim b/plugin/magit.vim
index dfc06a3b6af622f865132537bd6a020cd850a186..0f1a975cbb034bab15adcdde2ff00491d21f59ff 100644
--- a/plugin/magit.vim
+++ b/plugin/magit.vim
@@ -424,8 +424,8 @@ function! s:mg_create_diff_from_select(select_lines)
 	if ( start_select_line < starthunk || end_select_line > endhunk )
 		throw 'out of hunk selection'
 	endif
-	let section=<SID>mg_get_section()
-	let filename=<SID>mg_get_filename()
+	let section=magit#helper#get_section()
+	let filename=magit#helper#get_filename()
 	let hunks = b:state.get_file(section, filename).get_hunks()
 	for hunk in hunks
 		if ( hunk.header == getline(starthunk) )
@@ -479,57 +479,10 @@ function! s:mg_mark_lines_in_hunk(start_select_line, end_select_line)
 	return magit#sign#toggle_signs('M', a:start_select_line, a:end_select_line)
 endfunction
 
-" s:mg_get_section: helper function to get the current section, according to
-" cursor position
-" return: section id, empty string if no section found
-function! s:mg_get_section()
-	let section_line=getline(search(g:magit_section_re, "bnW"))
-	for [section_name, section_str] in items(g:magit_sections)
-		if ( section_line == section_str )
-			return section_name
-		endif
-	endfor
-	return ''
-endfunction
-
-" s:mg_get_filename: helper function to get the current filename, according to
-" cursor position
-" return: filename
-function! s:mg_get_filename()
-	return substitute(getline(search(g:magit_file_re, "cbnW")), g:magit_file_re, '\2', '')
-endfunction
-
-" s:mg_get_hunkheader: helper function to get the current hunk header,
-" according to cursor position
-" return: hunk header
-function! s:mg_get_hunkheader()
-	return getline(search(g:magit_hunk_re, "cbnW"))
-endfunction
-
 " }}}
 
 " {{{ User functions and commands
 
-" magit#open_close_folding_wrapper: wrapper function to
-" magit#open_close_folding. If line under cursor is not a cursor, execute
-" normal behavior
-" param[in] mapping: which has been set
-" param[in] visible : boolean, force visible value. If not set, toggle
-" visibility
-function! magit#open_close_folding_wrapper(mapping, ...)
-	if ( getline(".") =~ g:magit_file_re )
-		return call('magit#open_close_folding', a:000)
-	elseif ( foldlevel(line(".")) == 2 )
-		if ( foldclosed(line('.')) == -1 )
-			foldclose
-		else
-			foldopen
-		endif
-	else
-		silent! execute "silent! normal! " . a:mapping
-	endif
-endfunction
-
 " magit#open_close_folding()
 " param[in] visible : boolean, force visible value. If not set, toggle
 " visibility
@@ -539,7 +492,7 @@ function! magit#open_close_folding(...)
 		throw 'non file header line: ' . getline(".")
 	endif
 	let filename = list[2]
-	let section=<SID>mg_get_section()
+	let section=magit#helper#get_section()
 	" if first param is set, force visible to this value
 	" else, toggle value
 	let file = b:state.get_file(section, filename, 0)
@@ -906,7 +859,7 @@ function! s:mg_stage_closed_file(discard)
 	if ( getline(".") =~ g:magit_file_re )
 		let list = matchlist(getline("."), g:magit_file_re)
 		let filename = list[2]
-		let section=<SID>mg_get_section()
+		let section=magit#helper#get_section()
 		
 		let file = b:state.get_file(section, filename)
 		if ( file.is_visible() == 0 ||
@@ -966,8 +919,8 @@ endfunction
 " param[in] discard: boolean, if true, discard instead of (un)stage
 " return: no
 function! magit#stage_block(selection, discard) abort
-	let section=<SID>mg_get_section()
-	let filename=<SID>mg_get_filename()
+	let section=magit#helper#get_section()
+	let filename=magit#helper#get_filename()
 
 	let file = b:state.get_file(section, filename, 0)
 	let header = file.get_header()
@@ -1122,7 +1075,7 @@ endfunction
 " magit#ignore_file: this function add the file under cursor to .gitignore
 " FIXME: git diff adds some strange characters to end of line
 function! magit#ignore_file() abort
-	let ignore_file=<SID>mg_get_filename()
+	let ignore_file=magit#helper#get_filename()
 	call magit#utils#append_file(magit#git#top_dir() . ".gitignore",
 			\ [ ignore_file ] )
 	call magit#update_buffer()
@@ -1148,7 +1101,7 @@ function! magit#commit_command(mode)
 	if ( a:mode == 'CF' )
 		call <SID>mg_git_commit(a:mode)
 	else
-		let section=<SID>mg_get_section()
+		let section=magit#helper#get_section()
 		if ( section == 'commit' &&
 \			!(b:magit_current_commit_mode == 'CC' && a:mode == 'CA' ) )
 			if ( b:magit_current_commit_mode == '' )
@@ -1245,9 +1198,9 @@ endfunction
 " if this file is already displayed in a window, jump to the window, if not,
 " jump to last window and open buffer, at the beginning of the hunk
 function! magit#jump_to()
-	let section=<SID>mg_get_section()
-	let filename=fnameescape(magit#git#top_dir() . <SID>mg_get_filename())
-	let line=substitute(s:mg_get_hunkheader(),
+	let section=magit#helper#get_section()
+	let filename=fnameescape(magit#git#top_dir() . magit#helper#get_filename())
+	let line=substitute(magit#helper#get_hunkheader(),
 				\ '^@@ -\d\+,\d\+ +\(\d\+\),\d\+ @@.*$', '\1', "")
 	let context = magit#git#get_config("diff.context", 3)
 	let line += context