Re: Cursor isn't at right position for Commit message

2017-06-08 Thread Ken Takata
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("$") &&  !~# '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("$") &&
> +\  !~# '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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cursor isn't at right position for Commit message

2017-06-06 Thread Bram Moolenaar

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("$") &&  !~# '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("$") &&
> +\  !~# 'commit' | exe "normal! g`\"" | endif
>  
>  line2byte({lnum})  *line2byte()*
> Return the byte count from the start of the buffer for line

I suppose that this is better in most cases.  There might be some other
filetypes that only apply to temp files.

-- 
hundred-and-one symptoms of being an internet addict:
14. You start introducing yourself as "Jim at I-I-Net dot net dot au"

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cursor isn't at right position for Commit message

2017-06-06 Thread Christian Brabandt

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("$") &&  !~# '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("$") &&
+\  !~# 'commit' | exe "normal! g`\"" | endif
 
 line2byte({lnum})  *line2byte()*
Return the byte count from the start of the buffer for line


Best,
Christian
-- 
In feinen Gesellschaften wird nur der abwesende persifliert, in
gemeinen spaßet man über d(en) gegenwärtigen.
-- Jean Paul

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cursor isn't at right position for Commit message

2017-06-06 Thread Christian Brabandt

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

It could be, that your system sources defaults.vim which sets up the 
last-position-jump (see :h last-position-jump) autocommand.

Read :h defaults.vim how to prevent loading it (it is usually only 
loaded, when no vimrc has been found)

Best,
Christian
-- 
In jedem Falle wird bei gleicher Anlage das falsche Vertrauen auf
Talente mehr hervorbringen als das falsche Mißtrauen in sie; jenes
spannt, dieses lähmt.
-- Jean Paul

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cursor isn't at right position for Commit message

2017-06-05 Thread Eric Christopherson
On Sun, Jun 04, 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
> 
> --
> Regards,
> Kaartic Sivaraam 

Do you have an autocmd to resume the last position in a file when
opening that file later? I had one like that (I forget where I copied it
from), which I eventually modified to exclude gitcommit files. See the
solutions at
https://stackoverflow.com/questions/2393671/vim-restores-cursor-position-exclude-special-files
.

> 
> -- 
> -- 
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
Eric Christopherson

-- 
-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.