Skip to content

Commit

Permalink
plugin/magit.vim: commit message with standard write commands :w :x :…
Browse files Browse the repository at this point in the history
…wq ZZ (fix #91)
  • Loading branch information
jreybert committed Sep 14, 2016
1 parent 3fb0765 commit 36c277e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ Open magit buffer with [:Magit](#magitshow_magit) command.

#### CC

Once you have stage all the required changes, press **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, go back in Normal mode, and press **CC**: you created your first commit with vimagit!
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).

Voila! you created your first commit with vimagit!

## Usage

Expand Down Expand Up @@ -204,11 +206,13 @@ E means 'edit'.

##### 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.
* 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
* 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.

##### CF
* Amend the staged changes into the previous commit, without modifying previous commit message.
Expand Down
20 changes: 13 additions & 7 deletions doc/vimagit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ 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, press 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, go back in Normal mode, and press CC: you
created your first commit with vimagit!
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).

Voila! you created your first commit with vimagit!

===============================================================================
4. USAGE *vimagit-usage*
Expand Down Expand Up @@ -232,9 +233,14 @@ Following mappings are set locally, for magit buffer only, in normal mode.
*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
"Commit message" section with brand new commit message.
If in commit section, commit the all staged changes in commit mode
previously set.
"Commit message" section with brand new commit message.
If in commit section, create the commit with the commit message and
all staged changes.

*vimagit-:w* *magit#commit_command('CC')*
:w :x :wq ZZ
If in commit section, create the commit with the commit message and
all staged changes.

*vimagit-CA* *magit#commit_command('CA')*
*vimagit-g:magit_commit_amend_mapping*
Expand Down
10 changes: 9 additions & 1 deletion plugin/magit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ function! magit#update_buffer(...)
catch /^out_of_block$/
let b:magit_current_commit_msg = []
endtry
setlocal buftype=acwrite
else
setlocal buftype=nofile
setlocal nomodified
endif
" FIXME: find a way to save folding state. According to help, this won't
" help:
Expand Down Expand Up @@ -776,7 +780,9 @@ function! magit#show_magit(display, ...)
setlocal nobuflisted
let &l:foldlevel = b:magit_default_fold_level
setlocal filetype=magit
"setlocal readonly

execute "autocmd BufWriteCmd " . buffer_name . " :call magit#commit_command('CC')"


let b:state = deepcopy(g:magit#state#state)
" s:magit_commit_mode: global variable which states in which commit mode we are
Expand Down Expand Up @@ -1086,6 +1092,8 @@ function! magit#commit_command(mode)
else
let b:magit_current_commit_mode=a:mode
let b:magit_commit_newly_open=1
setlocal buftype=acwrite
setlocal nomodified
endif
endif
call magit#update_buffer()
Expand Down

0 comments on commit 36c277e

Please sign in to comment.