From d6527358e2959ac9082647b1f4c7c24db5f904f8 Mon Sep 17 00:00:00 2001 From: Jerome Reybert <jreybert@gmail.com> Date: Mon, 30 Jan 2017 00:14:01 +0100 Subject: [PATCH] Update main mappings to lower case (fix #101 #103) --- README.md | 77 ++++++++++----- autoload/magit/mapping.vim | 195 +++++++++++++++++++++++++++++++++++++ doc/vimagit.txt | 102 +++++++++++-------- plugin/magit.vim | 158 ++---------------------------- 4 files changed, 320 insertions(+), 212 deletions(-) create mode 100644 autoload/magit/mapping.vim diff --git a/README.md b/README.md index 53e85e9..ccce079 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ From a very single vim buffer, you can perform main git operations in few key pr Take a look at [TL;DR](#tldr) to start using it immediately. +**Important**: some default mapping have changed since version 1.7, see [mapping_update](#here). +  Some screencasts: @@ -53,15 +55,15 @@ To simply test vimagit, modify/add/delete/rename some files in a git repository - `:Magit` Open magit buffer with [:Magit](#magitshow_magit) command. -- `N` - Jump to next hunk with `N`, or move the cursor as you like. The cursor is on a hunk. -- `S` - While the cursor is on an unstaged hunk, press `S` in Normal mode: the hunk is now staged, and appears in "Staged changes" section (you can also unstage a hunk from "Staged section" with `S`). -- `CC` - Once you have stage all the required changes, press `CC`. +- `<C-n>` + Jump to next hunk with `<C-n>`, or move the cursor as you like. The cursor is on a hunk. +- `s` + While the cursor is on an unstaged hunk, press `s` in Normal mode: the hunk is now staged, and appears in "Staged changes" section (you can also unstage a hunk from "Staged section" with `s`). +- `cc` + Once you have stage all the required changes, press `cc`. - Section "Commit message" is shown. - Type your commit message in this section. - - To commit, go back in Normal mode, and press `CC` (or `:w` if you prefer). + - To commit, go back in Normal mode, and press `cc` (or `:w` if you prefer). You just created your first commit with vimagit! @@ -104,9 +106,9 @@ There are 5 sections: ### Visual selection It is possible to stage part of hunk, by different ways: -* By visually selecting some lines, then staging the selection with **S**. -* By marking some lines "to be staged" with **M**, then staging these selected lines with **S**. -* Staging individual lines with **L**. +* By visually selecting some lines, then staging the selection with **s**. +* By marking some lines "to be staged" with **m**, then staging these selected lines with **s**. +* Staging individual lines with **l**. Visual selection and marked lines have some limitations for the moment: * It only work for "staging", not for "unstaging". @@ -164,33 +166,33 @@ Following mappings are set locally, for magit buffer only, in normal mode. ##### zc,zC * Typing zc on a file will hide its diffs. -##### S +##### 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 (using **v**), stage only visual selected lines (only works for staging). - * If some lines in the hunk are marked (using **M**), stage only marked lines (only works for staging). + * If some lines in the hunk are marked (using **m**), stage only marked lines (only works for staging). * 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 +##### 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. -##### L +##### l * Stage the line under the cursor. -##### M +##### m * 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**. + * To staged marked lines in a hunk, move cursor to this hunk and press **s**. ##### 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. -##### E +##### 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 @@ -200,33 +202,33 @@ If cursor is in a hunk, cursor will move in the file containing this hunk, at * if there is only magit window opened, split vertically, moves cursor to new split and open buffer at the hunk line -E means 'edit'. +e means 'edit'. :exclamation: this function is extremely powerful, just give it a try! -##### N,P +##### <C-n>,<C-p> * Move to **N**ext or **P**revious hunk. -##### CC +##### 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, create the commit with the commit message and all staged changes. ##### :w :x :wq ZZ * If in commit section, create the commit with the commit message and all staged changes. -##### CA +##### ca * If not in commit section, set commit mode to "Amend commit" and show "Commit message" section with previous commit message. -##### CF +##### cf * Amend the staged changes into the previous commit, without modifying previous commit message. -##### CU - * Close a commit section (If you need soon after open or editing commit message, pressing 'u' is good enough). +##### cu + * Close a commit section ##### I * Add the file under the cursor in .gitgnore -##### R +##### r * Refresh magit buffer ##### -,+,0 @@ -238,6 +240,31 @@ E means 'edit'. ##### ? * Toggle help showing in magit buffer +#### Mapping update + +Since vimagit 1.7, main mappings have changed. For the majority, it is +only a case change: + * Stage hunk : **S** -> **s** + * Stage file : **F** -> **f** + * Stage line : **L** -> **l** + * Mark lines : **M** -> **m** + * Commit : **CC** -> **cc** + * Commit amend : **CA** -> **ca** + * Commit fix : **CF** -> **cf** + * Commit close : **CU** -> **cu** + * Reload : **R** -> **r** + * Edit : **E** -> **e** + +Jump between hunks now uses control + * Jump next hunk : **N** -> **<C-n>** + * Jump prev hunk : **P** -> **<C-p>** + +Ignore mapping (I) and discard mapping (DDD) are let unchanged. + +You can define your own mapping with the method descried below, or set the +following variable to keep the old mappings: +> let g:magit_keep_old_mapping = 1 + #### Autocommand events Magit will raise some events at some point. User can plug some specific diff --git a/autoload/magit/mapping.vim b/autoload/magit/mapping.vim new file mode 100644 index 0000000..f9f3236 --- /dev/null +++ b/autoload/magit/mapping.vim @@ -0,0 +1,195 @@ + +let s:user_mappings = {} + +function! s:print_map() + map <buffer> +endfunction + +function! magit#mapping#get_mappings() + " if ( empty(s:user_mappings) ) + redir => map_str + silent call s:print_map() + redir END + let map_array = filter(split(map_str, '\n'), 'v:val =~ "<Plug>\(magit"') + for line in map_array + let l=split(line, '\s\+') + let name=l[0]."_".substitute(l[2], '.\?<Plug>.*(\(magit.*\)).*', '\1', '') + let s:user_mappings[name]=l[1] + endfor + echo s:user_mappings + " endif +endfunction + + +if ( g:magit_keep_old_mapping ) + let g:magit_stage_file_mapping = get(g:, 'magit_stage_file_mapping', 'F' ) + let g:magit_stage_hunk_mapping = get(g:, 'magit_stage_hunk_mapping', 'S' ) + let g:magit_stage_line_mapping = get(g:, 'magit_stage_line_mapping', 'L' ) + let g:magit_mark_line_mapping = get(g:, 'magit_mark_line_mapping', 'M' ) + let g:magit_commit_mapping = get(g:, 'magit_commit_mapping', 'CC' ) + let g:magit_commit_amend_mapping = get(g:, 'magit_commit_amend_mapping', 'CA' ) + let g:magit_commit_fixup_mapping = get(g:, 'magit_commit_fixup_mapping', 'CF' ) + let g:magit_close_commit_mapping = get(g:, 'magit_close_commit_mapping', 'CU' ) + let g:magit_reload_mapping = get(g:, 'magit_reload_mapping', 'R' ) + let g:magit_edit_mapping = get(g:, 'magit_edit_mapping', 'E' ) + 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') +endif + +let g:magit_stage_file_mapping = get(g:, 'magit_stage_file_mapping', 'f' ) +let g:magit_stage_hunk_mapping = get(g:, 'magit_stage_hunk_mapping', 's' ) +let g:magit_stage_line_mapping = get(g:, 'magit_stage_line_mapping', 'l' ) +let g:magit_mark_line_mapping = get(g:, 'magit_mark_line_mapping', 'm' ) +let g:magit_commit_mapping = get(g:, 'magit_commit_mapping', 'cc' ) +let g:magit_commit_amend_mapping = get(g:, 'magit_commit_amend_mapping', 'ca' ) +let g:magit_commit_fixup_mapping = get(g:, 'magit_commit_fixup_mapping', 'cf' ) +let g:magit_close_commit_mapping = get(g:, 'magit_close_commit_mapping', 'cu' ) +let g:magit_reload_mapping = get(g:, 'magit_reload_mapping', 'r' ) +let g:magit_edit_mapping = get(g:, 'magit_edit_mapping', 'e' ) +let g:magit_jump_next_hunk = get(g:, 'magit_jump_next_hunk', '<C-N>') +let g:magit_jump_prev_hunk = get(g:, 'magit_jump_prev_hunk', '<C-P>') + +let g:magit_ignore_mapping = get(g:, 'magit_ignore_mapping', 'I' ) +let g:magit_discard_hunk_mapping = get(g:, 'magit_discard_hunk_mapping', 'DDD' ) + +let g:magit_close_mapping = get(g:, 'magit_close_mapping', 'q' ) +let g:magit_toggle_help_mapping = get(g:, 'magit_toggle_help_mapping', '?' ) + +let g:magit_diff_shrink = get(g:, 'magit_diff_shrink', '-' ) +let g:magit_diff_enlarge = get(g:, 'magit_diff_enlarge', '+' ) +let g:magit_diff_reset = get(g:, 'magit_diff_reset', '0' ) + +let g:magit_folding_toggle_mapping = get(g:, 'magit_folding_toggle_mapping', [ '<CR>' ]) +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' ]) + +function! magit#mapping#set_default() + + execute "nnoremap <buffer><silent> " . g:magit_stage_file_mapping . " :call magit#stage_file()<cr>" + execute "nnoremap <buffer><silent> " . g:magit_stage_hunk_mapping . " :call magit#stage_hunk(0)<cr>" + execute "nnoremap <buffer><silent> " . g:magit_discard_hunk_mapping . " :call magit#stage_hunk(1)<cr>" + execute "nnoremap <buffer><silent> " . g:magit_reload_mapping . " :call magit#update_buffer()<cr>" + execute "nnoremap <buffer><silent> " . g:magit_edit_mapping . " :call magit#jump_to()<cr>" + execute "nnoremap <buffer><silent> " . g:magit_commit_mapping . " :call magit#commit_command('CC')<cr>" + execute "nnoremap <buffer><silent> " . g:magit_commit_amend_mapping . " :call magit#commit_command('CA')<cr>" + execute "nnoremap <buffer><silent> " . g:magit_commit_fixup_mapping . " :call magit#commit_command('CF')<cr>" + execute "nnoremap <buffer><silent> " . g:magit_close_commit_mapping . " :call magit#close_commit()<cr>" + execute "nnoremap <buffer><silent> " . g:magit_ignore_mapping . " :call magit#ignore_file()<cr>" + execute "nnoremap <buffer><silent> " . g:magit_close_mapping . " :call magit#close_magit()<cr>" + execute "nnoremap <buffer><silent> " . g:magit_diff_shrink . " :call magit#update_diff('-')<cr>" + execute "nnoremap <buffer><silent> " . g:magit_diff_enlarge . " :call magit#update_diff('+')<cr>" + execute "nnoremap <buffer><silent> " . g:magit_diff_reset . " :call magit#update_diff('0')<cr>" + execute "nnoremap <buffer><silent> " . g:magit_toggle_help_mapping . " :call magit#toggle_help()<cr>" + + execute "nnoremap <buffer><silent> " . g:magit_stage_line_mapping . " :call magit#stage_vselect()<cr>" + execute "xnoremap <buffer><silent> " . g:magit_stage_hunk_mapping . " :call magit#stage_vselect()<cr>" + + 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 + execute "nnoremap <buffer><silent> " . mapping . " :call magit#open_close_folding_wrapper('" . func_arg . "')<return>" + endfor + for mapping in g:magit_folding_open_mapping + execute "nnoremap <buffer><silent> " . mapping . " :call magit#open_close_folding_wrapper('" . mapping . "', 1)<return>" + endfor + for mapping in g:magit_folding_close_mapping + execute "nnoremap <buffer><silent> " . mapping . " :call magit#open_close_folding_wrapper('" . mapping . "', 0)<return>" + endfor + + " s:magit_inline_help: Dict containing inline help for each section + let s:magit_inline_help = { + \ 'staged': [ +\g:magit_stage_hunk_mapping +\.' if cursor on filename header, unstage file', +\' if cursor in hunk, unstage hunk', +\' if visual selection in hunk (with v), unstage selection', +\' if lines marked in hunk (with ' . g:magit_mark_line_mapping . '), unstage marked lines', +\g:magit_stage_line_mapping +\.' unstage the line under the cursor', +\g:magit_mark_line_mapping +\.' if cursor in hunk, mark line under cursor "to be unstaged"', +\' if visual selection in hunk (with v), mark selected lines "to be unstaged"', +\g:magit_stage_file_mapping +\.' if cursor on filename header or hunk, unstage whole file', +\g:magit_edit_mapping +\.' edit, jump cursor to file containing this hunk', +\g:magit_jump_next_hunk.','.g:magit_jump_prev_hunk +\. ' move to Next/Previous hunk in magit buffer', +\], + \ 'unstaged': [ +\g:magit_stage_hunk_mapping +\.' if cursor on filename header, stage file', +\' if cursor in hunk, stage hunk', +\' if visual selection in hunk (with v), stage selection', +\' if lines marked in hunk (with ' . g:magit_mark_line_mapping . '), stage marked lines', +\g:magit_stage_line_mapping +\.' stage the line under the cursor', +\g:magit_mark_line_mapping +\.' if cursor in hunk, mark line under cursor "to be staged"', +\' if visual selection in hunk (with v), mark selected lines "to be staged"', +\g:magit_stage_file_mapping +\.' if cursor on filename header or hunk, stage whole file', +\g:magit_edit_mapping +\.' edit, jump cursor to file containing this hunk', +\g:magit_jump_next_hunk.','.g:magit_jump_prev_hunk +\. ' move to Next/Previous hunk in magit buffer', +\g:magit_discard_hunk_mapping +\. ' discard file changes (warning, changes will be lost)', +\g:magit_ignore_mapping +\.' add file in .gitgnore', +\], + \ 'global': [ +\g:magit_folding_toggle_mapping[0] +\. ' if cursor on filename header line, unhide diffs for this file', +\g:magit_commit_mapping +\. ' set commit mode to normal, and show "Commit message" section', +\g:magit_commit_amend_mapping +\. ' set commit mode amend, and show "Commit message" section with previous', +\' commit message', +\g:magit_commit_fixup_mapping +\. ' amend staged changes to previous commit without modifying the previous', +\' commit message', +\g:magit_close_commit_mapping +\. ' commit undo, cancel and close current commit message', +\g:magit_reload_mapping +\.' refresh magit buffer', +\g:magit_diff_shrink.','.g:magit_diff_enlarge.','.g:magit_diff_reset +\. ' shrink,enlarge,reset diff context', +\g:magit_close_mapping +\.' close magit buffer', +\g:magit_toggle_help_mapping +\.' toggle help showing in magit buffer', +\], + \ 'commit': [ +\g:magit_commit_mapping +\. ' commit all staged changes with commit mode previously set (normal or', +\' amend) with message written in this section', +\], +\} +endfunction + +" s:mg_get_inline_help_line_nb: this function returns the number of lines of +" a given section, or 0 if help is disabled. +" param[in] section: section identifier +" return number of lines +function! magit#mapping#get_section_help_line_nb(section) + return ( g:magit_show_help == 1 ) ? + \ len(s:magit_inline_help[a:section]) : 0 +endfunction + +" s:mg_section_help: this function writes in current buffer the inline help +" for a given section, it does nothing if inline help is disabled. +" WARNING: this function writes in file, it should only be called through +" protected functions like magit#update_buffer +" param[in] section: section identifier +function! magit#mapping#get_section_help(section) + if ( g:magit_show_help == 1 ) + silent put =s:magit_inline_help[a:section] + endif +endfunction + diff --git a/doc/vimagit.txt b/doc/vimagit.txt index 2c80bb1..410de2a 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -53,21 +53,22 @@ repository and open vim. > :Magit Open magit buffer with :Magit command. -> N -Jump to next hunk with N. The cursor should be on the header of a hunk. +> <C-n> +Jump to next hunk with <C-n>. The cursor should be on the header of a hunk. -> S -If the hunk is in "Unstage changes" section, press S in Normal mode: the +> s +If the hunk is in "Unstage changes" section, press s in Normal mode: the hunk is now staged, and appears in "Staged changes" section. The opposite is also possible, i.e. unstage a hunk from "Staged section". -If you move the cursor to the file header and press S, the whole file is +If you move the cursor to the file header and press s, the whole file is staged. -> CC -Once you have stage all the required changes, type CC. A new section "Commit -message" appears and cursor move to it. Type your commit message, in Insert mode -this time. Once it's done, write your commit message with :w (or :x, :wq, ZZ). +> cc +Once you have stage all the required changes, press `cc`. + - Section "Commit message" is shown. + - Type your commit message in this section. + - To commit, go back in Normal mode, and press `cc` (or `:w` if you prefer). Voila! you created your first commit with vimagit! @@ -99,10 +100,10 @@ INLINE MODIFICATIONS *vimagit-inline-modification* VISUAL SELECTION *vimagit-visual-selection* It is possible to stage part of hunk, by different ways: -* By visually selecting some lines, then staging the selection with S. -* By marking some lines "to be staged" with M, then staging these selected - lines with S. -* Staging individual lines with L. +* By visually selecting some lines, then staging the selection with s. +* By marking some lines "to be staged" with m, then staging these selected + lines with s. +* Staging individual lines with l. Visual selection and marked lines have some limitations for the moment: * It only work for "staging", not for "unstaging". @@ -145,7 +146,33 @@ variable is described below as *vimagit-g:magit_nameofmapping_mapping* For example, to redefine the <leader>M mapping, user should add this line in its |vimrc|: -let g:magit_show_magit_mapping='itsnewmapping' +let g:magit_show_magit_mapping='m' + +Mapping update *vimagit-mapping-update* +-------------- + +Since vimagit 1.7, main mappings have changed. For the majority, it is +only a case change: + Stage hunk : S -> s + Stage file : F -> f + Stage line : L -> l + Mark lines : M -> m + Commit : CC -> cc + Commit amend : CA -> ca + Commit fix : CF -> cf + Commit close : CU -> cu + Reload : R -> r + Edit : E -> e + +Jump between hunks now uses control + Jump next hunk : N -> <C-n> + Jump prev hunk : P -> <C-p> + +Ignore mapping (I) and discard mapping (DDD) are let unchanged. + +You can define your own mapping with the method descried below, or set the +following variable to keep the old mappings: +let g:magit_keep_old_mapping = 1 Global mappings --------------- @@ -173,38 +200,38 @@ Following mappings are set locally, for magit buffer only, in normal mode. *vimagit-g:magit_folding_close_mapping* zc,zC Typing zc on a file will hide its diffs. - *vimagit-S* *magit#stage_hunk(0)* + *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 only selected lines (only works for staging). - If some lines in the hunk are marked (see |vimagit-M|), stage only + If some lines in the hunk are marked (see |vimagit-m|), stage only these lines (only works for staging). 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. - *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) + *vimagit-l* + l Stage the line under the cursor (only works for staging) - *vimagit-M* - M + *vimagit-m* + 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 + To staged marked lines, press s (see |vimagit-s|) in the current hunk. *vimagit-DDD* *magit#stage_hunk(1)* @@ -226,15 +253,15 @@ 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-N* *magit#jump_hunk()* - *vimagit-P* + *vimagit-<C-n>* *magit#jump_hunk()* + *vimagit-<C-p>* *vimagit-g:magit_jump_next_hunk* *vimagit-g:magit_jump_prev_hunk* - N,P Move to Next or Previous hunk. + <C-n>,<C-p> Move to Next or Previous hunk. - *vimagit-CC* *magit#commit_command('CC')* + *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 + 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, create the commit with the commit message and all staged changes. @@ -244,30 +271,29 @@ Following mappings are set locally, for magit buffer only, in normal mode. If in commit section, create the commit with the commit message and all staged changes. - *vimagit-CA* *magit#commit_command('CA')* + *vimagit-ca* *magit#commit_command('CA')* *vimagit-g:magit_commit_amend_mapping* - CA If not in commit section, set commit mode to "Amend commit" and + ca If not in commit section, set commit mode to "Amend commit" and show "Commit message" section with previous commit message. If in commit section, commit the staged changes in commit mode previously set. - *vimagit-CF* *magit#commit_command('CF')* + *vimagit-cf* *magit#commit_command('CF')* *vimagit-g:magit_commit_fixup_mapping* - CF Amend the staged changes into the previous commit, without + cf Amend the staged changes into the previous commit, without modifying previous commit message - *vimagit-CU* *magit#close_commit()* + *vimagit-cu* *magit#close_commit()* *vimagit-g:magit_close_commit_mapping* - CU Close a commit section (If you need soon after open or editing - Ucommit message, pressing 'u' is good enough). + cu Close a commit section *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-r* *magit#update_buffer()* *vimagit-g:magit_reload_mapping* - R Refresh magit buffer. + r Refresh magit buffer. *magit#update_diff()* *vimagit--* *vimagit-g:magit_diff_shrink* diff --git a/plugin/magit.vim b/plugin/magit.vim index c1d2c6a..25564d7 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -21,32 +21,6 @@ execute 'source ' . g:vimagit_path . '/../common/magit_common.vim' " these mappings are broadly applied, for all vim buffers let g:magit_show_magit_mapping = get(g:, 'magit_show_magit_mapping', '<leader>M' ) -" these mapping are applied locally, for magit buffer only -let g:magit_stage_file_mapping = get(g:, 'magit_stage_file_mapping', 'F' ) -let g:magit_stage_hunk_mapping = get(g:, 'magit_stage_hunk_mapping', 'S' ) -let g:magit_stage_line_mapping = get(g:, 'magit_stage_line_mapping', 'L' ) -let g:magit_mark_line_mapping = get(g:, 'magit_mark_line_mapping', 'M' ) -let g:magit_discard_hunk_mapping = get(g:, 'magit_discard_hunk_mapping', 'DDD' ) -let g:magit_commit_mapping = get(g:, 'magit_commit_mapping', 'CC' ) -let g:magit_commit_amend_mapping = get(g:, 'magit_commit_amend_mapping', 'CA' ) -let g:magit_commit_fixup_mapping = get(g:, 'magit_commit_fixup_mapping', 'CF' ) -let g:magit_close_commit_mapping = get(g:, 'magit_close_commit_mapping', 'CU' ) -let g:magit_reload_mapping = get(g:, 'magit_reload_mapping', 'R' ) -let g:magit_edit_mapping = get(g:, 'magit_edit_mapping', 'E' ) -let g:magit_ignore_mapping = get(g:, 'magit_ignore_mapping', 'I' ) -let g:magit_close_mapping = get(g:, 'magit_close_mapping', 'q' ) -let g:magit_toggle_help_mapping = get(g:, 'magit_toggle_help_mapping', '?' ) - -let g:magit_diff_shrink = get(g:, 'magit_diff_shrink', '-' ) -let g:magit_diff_enlarge = get(g:, 'magit_diff_enlarge', '+' ) -let g:magit_diff_reset = get(g:, 'magit_diff_reset', '0' ) - -let g:magit_folding_toggle_mapping = get(g:, 'magit_folding_toggle_mapping', [ '<CR>' ]) -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) @@ -60,6 +34,8 @@ let g:magit_refresh_gutter = get(g:, 'magit_refresh_gutter' , let g:magit_refresh_gitgutter = get(g:, 'magit_refresh_gitgutter', 0) let g:magit_warning_max_lines = get(g:, 'magit_warning_max_lines', 10000) +let g:magit_keep_old_mapping = get(g:, 'magit_keep_old_mapping', 0) + let g:magit_git_cmd = get(g:, 'magit_git_cmd' , "git") execute "nnoremap <silent> " . g:magit_show_magit_mapping . " :call magit#show_magit('v')<cr>" @@ -74,88 +50,6 @@ if (g:magit_refresh_gutter == 1 || g:magit_refresh_gitgutter == 1) endif " }}} -" {{{ Internal functions - -" s:magit_inline_help: Dict containing inline help for each section -let s:magit_inline_help = { - \ 'staged': [ -\g:magit_stage_hunk_mapping -\.' if cursor on filename header, unstage file', -\' if cursor in hunk, unstage hunk', -\g:magit_stage_file_mapping -\.' if cursor on filename header or hunk, unstage whole file', -\], - \ 'unstaged': [ -\g:magit_stage_hunk_mapping -\.' if cursor on filename header, stage file', -\' if cursor in hunk, stage hunk', -\' if visual selection in hunk (with v), stage selection', -\' if lines marked in hunk (with M), stage marked lines', -\g:magit_stage_line_mapping -\.' stage the line under the cursor', -\g:magit_mark_line_mapping -\.' if cursor in hunk, mark line under cursor "to be staged"', -\' if visual selection in hunk (with v), mark selected lines "to be' -\' staged"', -\g:magit_stage_file_mapping -\.' if cursor on filename header or hunk, stage whole file', -\g:magit_edit_mapping -\.' edit, jump cursor to file containing this hunk', -\g:magit_jump_next_hunk.','.g:magit_jump_prev_hunk -\. ' move to Next/Previous hunk in magit buffer', -\g:magit_discard_hunk_mapping -\. ' discard file changes (warning, changes will be lost)', -\g:magit_ignore_mapping -\.' add file in .gitgnore', -\], - \ 'global': [ -\g:magit_folding_toggle_mapping[0] -\. ' if cursor on filename header line, unhide diffs for this file', -\g:magit_commit_mapping -\. ' set commit mode to normal, and show "Commit message" section', -\g:magit_commit_amend_mapping -\. ' set commit mode amend, and show "Commit message" section with previous', -\' commit message', -\g:magit_commit_fixup_mapping -\. ' amend staged changes to previous commit without modifying the previous', -\' commit message', -\g:magit_close_commit_mapping -\. ' commit undo, cancel and close current commit message', -\g:magit_reload_mapping -\.' refresh magit buffer', -\g:magit_diff_shrink.','.g:magit_diff_enlarge.','.g:magit_diff_reset -\. ' shrink,enlarge,reset diff context', -\g:magit_close_mapping -\.' close magit buffer', -\g:magit_toggle_help_mapping -\.' toggle help showing in magit buffer', -\], - \ 'commit': [ -\g:magit_commit_mapping -\. ' commit all staged changes with commit mode previously set (normal or', -\' amend) with message written in this section', -\], -\} - -" s:mg_get_inline_help_line_nb: this function returns the number of lines of -" a given section, or 0 if help is disabled. -" param[in] section: section identifier -" return number of lines -function! s:mg_get_inline_help_line_nb(section) - return ( g:magit_show_help == 1 ) ? - \ len(s:magit_inline_help[a:section]) : 0 -endfunction - -" s:mg_section_help: this function writes in current buffer the inline help -" for a given section, it does nothing if inline help is disabled. -" WARNING: this function writes in file, it should only be called through -" protected functions like magit#update_buffer -" param[in] section: section identifier -function! s:mg_section_help(section) - if ( g:magit_show_help == 1 ) - silent put =s:magit_inline_help[a:section] - endif -endfunction " s:mg_get_info: this function writes in current buffer current git state " WARNING: this function writes in file, it should only be called through @@ -175,6 +69,7 @@ function! s:mg_get_info() \ . g:magit_commit_mode[b:magit_current_commit_mode] endif silent put ='' + silent put ='Some default mapping have changed, see :help vimagit-mapping-update' silent put ='Press ? to display help' endfunction @@ -231,7 +126,7 @@ endfunction function! s:mg_get_staged_section(mode) silent put ='' silent put =g:magit_sections[a:mode] - call <SID>mg_section_help(a:mode) + call magit#mapping#get_section_help(a:mode) silent put =magit#utils#underline(g:magit_sections[a:mode]) silent put ='' call s:mg_display_files(a:mode, '', 0) @@ -276,7 +171,7 @@ function! s:mg_get_commit_section() if ( b:magit_current_commit_mode != '' ) silent put ='' silent put =g:magit_sections.commit - call <SID>mg_section_help('commit') + call magit#mapping#get_section_help('commit') silent put =magit#utils#underline(g:magit_sections.commit) let git_dir=magit#git#git_dir() @@ -354,7 +249,7 @@ function! s:mg_get_commit_msg(...) let commit_section_pat_start='^'.g:magit_sections.commit.'$' " Get next section pattern with g:magit_default_sections order let commit_section_pat_end='^'.g:magit_sections[g:magit_default_sections[match(g:magit_default_sections, 'commit')+1]].'$' - let commit_jump_line = 2 + <SID>mg_get_inline_help_line_nb('commit') + let commit_jump_line = 2 + magit#mapping#get_section_help_line_nb('commit') let out_of_block = a:0 == 1 ? a:1 : 0 if ( out_of_block ) let old_pos=line('.') @@ -611,7 +506,7 @@ let g:magit_last_updated_buffer = '' " This Dict should be accessed through g:magit_default_sections let s:mg_display_functions = { \ 'info': { 'fn': function("s:mg_get_info"), 'arg': []}, - \ 'global_help': { 'fn': function("s:mg_section_help"), 'arg': ['global']}, + \ 'global_help': { 'fn': function("magit#mapping#get_section_help"), 'arg': ['global']}, \ 'commit': { 'fn': function("s:mg_get_commit_section"), 'arg': []}, \ 'staged': { 'fn': function("s:mg_get_staged_section"), 'arg': ['staged']}, \ 'unstaged': { 'fn': function("s:mg_get_staged_section"), 'arg': ['unstaged']}, @@ -702,7 +597,7 @@ function! magit#update_buffer(...) if ( b:magit_current_commit_mode != '' && b:magit_commit_newly_open == 1 ) let commit_section_pat_start='^'.g:magit_sections.commit.'$' silent! let section_line=search(commit_section_pat_start, "w") - silent! call cursor(section_line+2+<SID>mg_get_inline_help_line_nb('commit'), 0) + silent! call cursor(section_line+2+magit#mapping#get_section_help_line_nb('commit'), 0) if exists('#User#VimagitEnterCommit') doautocmd User VimagitEnterCommit endif @@ -857,42 +752,7 @@ function! magit#show_magit(display, ...) call magit#utils#setbufnr(bufnr(buffer_name)) call magit#sign#init() - execute "nnoremap <buffer> <silent> " . g:magit_stage_file_mapping . " :call magit#stage_file()<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_stage_hunk_mapping . " :call magit#stage_hunk(0)<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_discard_hunk_mapping . " :call magit#stage_hunk(1)<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_reload_mapping . " :call magit#update_buffer()<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_edit_mapping . " :call magit#jump_to()<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_commit_mapping . " :call magit#commit_command('CC')<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_commit_amend_mapping . " :call magit#commit_command('CA')<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_commit_fixup_mapping . " :call magit#commit_command('CF')<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_close_commit_mapping . " :call magit#close_commit()<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_ignore_mapping . " :call magit#ignore_file()<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_close_mapping . " :call magit#close_magit()<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_diff_shrink . " :call magit#update_diff('-')<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_diff_enlarge . " :call magit#update_diff('+')<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_diff_reset . " :call magit#update_diff('0')<cr>" - execute "nnoremap <buffer> <silent> " . g:magit_toggle_help_mapping . " :call magit#toggle_help()<cr>" - - execute "nnoremap <buffer> <silent> " . g:magit_stage_line_mapping . " :call magit#stage_vselect()<cr>" - execute "xnoremap <buffer> <silent> " . g:magit_stage_hunk_mapping . " :call magit#stage_vselect()<cr>" - - 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 - execute "nnoremap <buffer> <silent> " . mapping . " :call magit#open_close_folding_wrapper('" . func_arg . "')<cr>" - endfor - for mapping in g:magit_folding_open_mapping - execute "nnoremap <buffer> <silent> " . mapping . " :call magit#open_close_folding_wrapper('" . mapping . "', 1)<cr>" - endfor - for mapping in g:magit_folding_close_mapping - execute "nnoremap <buffer> <silent> " . mapping . " :call magit#open_close_folding_wrapper('" . mapping . "', 0)<cr>" - endfor + call magit#mapping#set_default() if exists('#User#VimagitBufferInit') doautocmd User VimagitBufferInit -- GitLab