Open Merovius opened 4 years ago
Hmm strange because the following works for me:
cd $(mktemp -d)
export HOME=$PWD
git clone https://github.com/govim/govim.git ~/.vim/pack/plugins/start/govim
cp ~/.vim/pack/plugins/start/govim/cmd/govim/config/minimal.vimrc .vimrc
git clone --single-branch https://github.com/golang/go.git
cd go/src/
git checkout 6f7b96f6cb5f5c156cf4e69b1fa1ec0e57b01677
Followed by:
vim cmd/link/internal/ld/lib.go +123
and then
vim cmd/link/internal/ld/lib.go +234
The only difference I notice is that your repro is missing a minimal .vimrc
?
Hmmmmm, so, this might be more confusing. Your steps also break for me. Same symptoms: File opens at last opened location, or line 1. If I remove govim, it works fine.
Now I'm wondering whether this has anything to do with vim-configs that ship with Fedora (had issues with that before, can't find a way to reliably disable them)… But it still is also definitely interacting with something govim is doing :)
Okay, so I just noticed that this doesn't even just affect .go
files. This also reproduces for me:
cd $(mktemp -d)
export HOME=$PWD
git clone https://github.com/govim/govim.git ~/.vim/pack/plugins/start/govim
cp ~/.vim/pack/plugins/start/govim/cmd/govim/config/minimal.vimrc .vimrc
vim .vimrc +3
Should open at line 3 - opens at line 1 instead. rm -rf ~/.vim/pack/plugins/start/govim
makes it work.
Okay, using a clean fedora image works to reproduce the issue:
mero@vetinari ~$ sudo docker run -it fedora:latest /bin/bash
[root@f0d3889f286b ~]# dnf install git vim golang
[root@f0d3889f286b ~]# cd $(mktemp -d)
[root@f0d3889f286b ~]# export HOME=$PWD
[root@f0d3889f286b ~]# git clone https://github.com/govim/govim.git ~/.vim/pack/plugins/start/govim
[root@f0d3889f286b ~]# cp ~/.vim/pack/plugins/start/govim/cmd/govim/config/minimal.vimrc .vimrc
[root@f0d3889f286b ~]# vim .vimrc +3
Definitely confirmed as being something to do with the Fedora-shipped Vim files:
If you:
sudo docker run -it fedora:latest /bin/bash
then:
dnf install -y git vim golang
cd $(mktemp -d)
export HOME=$PWD
git clone https://github.com/govim/govim.git ~/.vim/pack/plugins/start/govim
cp ~/.vim/pack/plugins/start/govim/cmd/govim/config/minimal.vimrc .vimrc
vim -u .vimrc .vimrc +3
everything works.
If you run:
vim -V15/tmp/debug.vim .vimrc +3
you will find what appears to be the culprit in the log:
sourcing "/etc/vimrc"
If you delete /etc/vimrc
then try:
vim .vimrc +3
everything works as expected.
Thanks for the repro BTW - made debugging that significantly easier.
For the record, the issue here is the following lines from /etc/vimrc
:
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup fedora
autocmd!
" In text files, always limit the width of text to 78 characters
" autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks
autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
" start with spec file template
" 1724126 - do not open new file with .spec suffix with spec file template
" apparently there are other file types with .spec suffix, so disable the
" template
" autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
augroup END
endif
It's unclear to my why the Fedora packaging folks want to enforce such a default behaviour on restoring cursor position, but I think that's a question best taken up with them.
The least invasive way of working around this without influencing the other Fedora defaults is to add the following at the top of your .vimrc
:
au! fedora BufReadPost
Hm… I'd like to ask you to reopen. Because 1. I already remove all fedora
and redhat
(and just to be sure just all) autocommands at the top of my .vimrc
, precisely because I don't like their defaults, but 2. it turns out I actually have that specific setting in my .vimrc, because I like the behavior in general :)
Without govim, while it does open a file on the last used location when just opening it, giving a specific location on the command line still overwrites it. But govim somehow messes with this, by always using the last location. I suggest trying that out in the docker container (without removing the fedora defaults):
dnf install vim golang git
git clone https://github.com/govim/govim.git ~/.vim/pack/plugins/start/govim
cp ~/.vim/pack/plugins/start/govim/cmd/govim/config/minimal.vimrc ~/.vimrc
rm -rf ~/.vim/pack/plugins/start/govim # yeah, I know, I'm going minimum effort here to get a well-known text file
vim ~/.vimrc +13 # opens on line 13
vim ~/.vimrc # opens on line 13 again
vim ~/.vimrc +23 # opens on line 23
git clone https://github.com/govim/govim.git ~/.vim/pack/plugins/start/govim
vim ~/.vimrc # opens on line 23
vim ~/.vimrc +42 # still line 23, should be 42
IMO there is still a bug with govim
here.
[edit] sorry, couple edits to the series of commands, been sloopy [/edit]
it turns out I actually have that specific setting in my .vimrc, because I like the behavior in general :)
Ah, well that changes everything!
Re-opening and will try and take a look what's going on. But my wild guess would be that it's something to do with multiple autocommands interacting badly with each other.
Frustratingly, whilst trying to reproduce this with logging via:
vi -V9/tmp/vim.debug .vimrc +5
the problem does not reproduce!
What version of Vim/Gvim are you using?
Vim/Gvim version
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat version/commit of
govim
are you using?806674b9d799bebda41122ce143c234e961bbc97
What is the output of
:messages
in Vim?Do the Vim channel,
govim
orgopls
log files show anything interesting?gopls.txt govim.txt vim_channel.txt
How did you install
govim
?Vim 8 packages
What did you do?
What did you expect to see?
vim first opening
lib.go
on line 123, then on line 234What did you see instead?
vim first opening
lib.go
on line 123, then on line 123 again. i.e. vim opens a go-file on the last opened position (or 0), instead of the one provided on the command-line, once govim was installed.