Skip to content

Commit

Permalink
Update main mappings to lower case (fix #101 #103)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreybert committed Jan 29, 2017
1 parent c4146ed commit d652735
Show file tree
Hide file tree
Showing 4 changed files with 320 additions and 212 deletions.
77 changes: 52 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

![Example of vimagit 1.5.1](../gh-pages/images/vimagit_screenshot_1.5.1.png?raw=true "Example of vimagit 1.5.1")

Some screencasts:
Expand Down Expand Up @@ -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!

Expand Down Expand Up @@ -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".
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
195 changes: 195 additions & 0 deletions autoload/magit/mapping.vim
Original file line number Diff line number Diff line change
@@ -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

Loading

0 comments on commit d652735

Please sign in to comment.