Hi,
2017/6/6 Tue 16:19:18 UTC+9 Christian Brabandt wrote:
> On So, 04 Jun 2017, Kaartic Sivaraam wrote:
>
> > Hello all,
> >
> > I am currently using Vim 8.0. When I use vim as my preferred editor for
> > git.
> >
> > When I try to commit a change in git it open up vim to type the commit
> > message. Most of the time the text cursor seems to be positioned
> > somewhere in the middle of the commit template (the comments). As a
> > result, I am unable to type in the commit message directly after
> > switching to "insert" mode in vim. Any reasons for this misbehaviour ?
> >
> > Environments:
> > Operating System: Debian GNU/Linux 9 (stretch)
> > Shell: bash
>
> Perhaps, we should disable the last-position jump for commit messages in
> general. Here is a patch:
>
> diff --git a/runtime/defaults.vim b/runtime/defaults.vim
> index 6fd43db51..fdac666e6 100644
> --- a/runtime/defaults.vim
> +++ b/runtime/defaults.vim
> @@ -109,7 +109,7 @@ if has("autocmd")
> " Don't do it when the position is invalid or when inside an event handler
> " (happens when dropping a file on gvim).
> autocmd BufReadPost *
> - \ if line("'\"") >= 1 && line("'\"") <= line("$") |
> + \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' |
> \ exe "normal! g`\"" |
> \ endif
>
> diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
> index a0cc971fe..b4b6bbfef 100644
> --- a/runtime/doc/eval.txt
> +++ b/runtime/doc/eval.txt
> @@ -5460,7 +5460,8 @@ line({expr}) The result is a Number, which is the line number of the file
> < *last-position-jump*
> This autocommand jumps to the last known position in a file
> just after opening it, if the '" mark is set: >
> - :au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
> + :au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") &&
> + \ &ft !~# 'commit' | exe "normal! g`\"" | endif
>
> line2byte({lnum}) *line2byte()*
> Return the byte count from the start of the buffer for line
I write the following setting in my .vimrc to avoid the problem:
augroup vimrc-git
autocmd!
autocmd BufRead {COMMIT_EDITMSG,MERGE_MSG,git-rebase-todo,NOTES_EDITMSG}
\ delmarks \" | 1
augroup END
Another option is changing the setting of Git to always open the first line:
$ git config --global core.editor "vim +1"
Regards,
Ken Takata
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment