Closed zjturner closed 7 years ago
I think this is related to this part of /etc/vimrc
:
"Remember the positions in files with some git-specific exceptions"
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$")
\ && expand("%") !~ "COMMIT_EDITMSG"
\ && expand("%") !~ "ADD_EDIT.patch"
\ && expand("%") !~ "addp-hunk-edit.diff"
\ && expand("%") !~ "git-rebase-todo" |
\ exe "normal g`\"" |
\ endif
I could imagine that there are other basenames we need to add. Could you see whether you can find out what is the precise file name of the file to be edited, next time this happens?
Attached is a screenshot of my window immediately upon typing git commit
. You can see the filename at the bottom, and you can see the cursor about halfway down in the first column. It seems plausible that the above code is related, but the filename seems to match the pattern, so maybe this code isn't being executed for some reason?
Note that this seems to be a regression. I recently upgraded from 2.10 and did not have this problem.
It definitely does seem to be related to remembering the file position. If I do git commit
, type an arbitrary commit message, then make a trivial change and use git commit --amend
the cursor is usually on the last character of the previously typed commit message, which implies the remembering logic is not working.
That said, I don't know anything about editing .vimrc
files by hand, so I can't tell if it's a bug in the .vimrc
file or a bug in vim
itself.
I just had a quick look and it would appear that expand("%")
expands to the full path.
Could you try the following: in C:\Program Files\Git\etc\vimrc
, change the expand("%")
calls by expand("%:t")
in the part to which I referred earlier.
Note: you will have to edit the file as administrator. The easiest way may be to right-click on Git CMD in the Start Menu, select Run as Administrator and then call git config -f "C:\Program Files\Git\etc\vimrc" -e
.
Sidenote: I got that information from http://vimdoc.sourceforge.net/htmldoc/eval.html#expand(), and I tried it out using :echom expand("%:t")
in vim.
If that change fixes the symptoms on your side, I will take it from there.
I have the same problem. I tried replacing all the "%"
with "%:t"
in /etc/vimrc
and it didn't make any difference. I added an echom
inside the if
to see if it's actually running the normal g
command, and after your suggested change, it is not running it, but the cursor position is still updated.
There is suspicious looking code in /usr/share/vim/vim80/defaults.vim
that does a similar thing. This file is sourced if there is no ~/.vimrc
, which is new behaviour is Vim 8.0.
So, to fix this, simply create ~/.vimrc
(it can be empty)/
Might be a good idea to add "MERGE_MSG" to the list as well.
@toby-allsopp good point about that new defaults.vim
feature. It's not the first time this has caused surprise.
I tried to disable the vimStartup
autogroup, as recommended, but as I did it in /etc/vimrc
(and that file is parsed before defaults.vim
) it did not work.
Now, I could skip the defaults.vim
entirely by defining skip_defaults_vim
, but that seems quite a bit heavy-handed.
Probably the best I can do is to edit defaults.vim
via git-extra
's post-install script. Ugly, but probably would work...
It seems that this problem is known upstream also: https://github.com/vim/vim/commit/9a48961d8bd7ffea14330b9b0181a6cdbe9288f7
It seems that this problem is known upstream also: vim/vim@9a48961
Thanks. This is only half a solution, though, as it does not take into account other file types that need adjusting... So I am relatively comfortable with the workaround I implemented.
Setup
Nothing
Details
cmd
Expected a vim window to be open with a pending commit message and the cursor in the upper left corner.
The problem is non-deterministic. I can do the same thing 5 times and the problem might only happen once. But the cursor will be on the first column of a random line. Pressing i to start typing a commit message then starts editing in the middle of the auto-generated commit-message comments.
I don't think it's repository specific, but regardless I am using this repository
https://github.com/llvm-project/llvm-project-20170507.git
.Here is my entire git config.