diff --git a/README.md b/README.md index dfdb4002733ce05bb05de7bf148c070da8728fe6..9fff9a93be7c9a22a43be59df83b22215ef8b585 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,9 @@ Open magit buffer. All files diffs are hidden by default. To inspect changes in a file, move cursor to the filename line, and press 'Enter' in Normal mode. Diffs are displayed below the file name. +#### N +* Jump to next hunk with **N**. + #### S * Modify a file, for example foo.c, in your repository. @@ -184,6 +187,9 @@ Following mappings are set locally, for magit buffer only, in normal mode. * If cursor is in diff header, discard whole file at cursor position. * Only works in "Unstaged changes" section. +##### N,P + * Move to **N**ext or **P**revious hunk. + ##### CC * If not in commit section, set commit mode to "New commit" and show "Commit message" section with brand new commit message. * If in commit section, commit the all staged changes in commit mode previously set. diff --git a/doc/vimagit.txt b/doc/vimagit.txt index 5d8d65fc8aba2b9c7e470890b0aa10f38071bbcf..fb6576d15a9c4c4b83e4985030aafee131f821f9 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -59,6 +59,11 @@ All files diffs are hidden by default. To inspect changes in a file, move cursor to the filename line, and press 'Enter' in Normal mode. Diffs are displayed below the file name. + N +----------- + +* Jump to next hunk with N. + S ----------- @@ -223,6 +228,10 @@ Following mappings are set locally, for magit buffer only, in normal mode. position. Only works in "Unstaged changes" section. + *vimagit-N* *magit#jump_hunk()* + *vimagit-P* + N,P Move to Next or Previous hunk. + *vimagit-CC* *magit#commit_command('CC')* *vimagit-g:magit_commit_mapping* CC If not in commit section, set commit mode to "New commit" and show diff --git a/plugin/magit.vim b/plugin/magit.vim index 96595beab97b024cc00726627eda0612a97e2812..9c2697bbd4ccfd840b448d7dc68b5c59be574e63 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -38,6 +38,8 @@ 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' ]) +let g:magit_jump_next_hunk = get(g:, 'magit_jump_next_hunk', 'N') +let g:magit_jump_prev_hunk = get(g:, 'magit_jump_prev_hunk', 'P') " user options let g:magit_enabled = get(g:, 'magit_enabled', 1) let g:magit_show_help = get(g:, 'magit_show_help', 0) @@ -665,7 +667,10 @@ function! magit#show_magit(display, ...) execute "nnoremap <buffer> <silent> " . g:magit_mark_line_mapping . " :call magit#mark_vselect()<cr>" execute "xnoremap <buffer> <silent> " . g:magit_mark_line_mapping . " :call magit#mark_vselect()<cr>" - + + execute "nnoremap <buffer> <silent> " . g:magit_jump_next_hunk . " :call magit#jump_hunk('N')<cr>" + execute "nnoremap <buffer> <silent> " . g:magit_jump_prev_hunk . " :call magit#jump_hunk('P')<cr>" + 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 @@ -918,6 +923,28 @@ function! magit#commit_command(mode) call magit#update_buffer() endfunction +" magit#jump_hunk: function to jump among hunks +" it closes the current fold (if any), jump to next hunk and unfold it +" param[in] dir: can be 'N' (for next) or 'P' (for previous) +function! magit#jump_hunk(dir) + let back = ( a:dir == 'P' ) ? 'b' : '' + let line = search("^@@ ", back . 'wn') + if ( line != 0 ) + try + foldclose + catch /^Vim\%((\a\+)\)\=:E490/ + endtry + call cursor(line, 0) + try + foldopen + catch /^Vim\%((\a\+)\)\=:E490/ + echohl WarningMsg + echom "Warning: you should have jumped on a folded hunk" + echohl None + endtry + endif +endfunction + command! Magit call magit#show_magit('v') command! MagitOnly call magit#show_magit('c')