Write a Git commit message in a new Vim window, then copy everything to Vim

I have these Vim mappings for Git. Most of the commands below work, but the last g mone does not work at all. I want to open a new Vim (preferably with an already loaded git message template, in accordance with the default behavior of the terminal), edit and save my message, and then commit.

Any ideas for another way to approach this?

" git shortcuts
"" show diff in new window
if has("gui_running")
  noremap gd :!git diff <BAR> gvim -<CR><CR>
else
  noremap gd :!git diff <BAR> vim -<CR><CR>
endif
noremap gs :!git status<CR>
noremap ga :!git add %<CR>
"" edit commit message in new window
if has("gui_running")
  noremap gm :!gvim __vim_gitcommitmessage && git commit -F __vim_gitcommitmessage && rm __vim_gitcommitmessage<CR>
else
  noremap gm :!vim __vim_gitcommitmessage && git commit -F __vim_gitcommitmessage && rm __vim_gitcommitmessage<CR>
endif

Update:

As suggested by VonC, I am now using fugitive.vim . I replaced previous Vim bindings and recommended this plugin to anyone using Vim and Git.

" fugitive shortcuts
noremap ggs :Gstatus<cr>
noremap ggc :Gcommit<cr>
noremap gga :Gwrite<cr>
noremap ggl :Glog<cr>
noremap ggd :Gdiff<cr>
+3
source share
2

Vim Git, Git :

, , fugitive.vim: . :

:MinSCMCommitTracked[!]         (Default mapping: \s<C-c>)

. .

            Used SCM commands ~
            hg  : commit
            git : commit -a
            bzr : commit

:MinSCMCommitAll[!]             (Default mapping: \sc)

. .

|: MinSCMCommitTracked | .

            Used SCM commands ~
            hg  : commit -A
            git : add -a && commit -a
            bzr : add && commit

, , , , Vim script.

+4

, git ? - git commit, vim, , ? , , git commit -e -F <template file>.

+1

Source: https://habr.com/ru/post/1760657/


All Articles