Comments (32)
I think, if there's no solution for this, people should be warned about this when using auto formatting on saving the file. I'll stop using it, as I have given up once before, because undo & redo is more important for me =)
from vim-go.
Well first you don't have to use it if you don't want it. But thanks for pointing out this bug. I wasn't aware of this. Therefore you shouldn't be angry to me, which I think you are and I found your tone not good.
If people don't want to use that's their business, however people do like this plugin and they try to help me and also contribute to this plugin. You could try to contribute instead of being sad or angry.
However I've looked add this and seems andrews repo fixes this, here is an experimental branch test it out and see if it works for your:
https://github.com/fatih/vim-go/tree/experimental-fmt (i've pushed quickly, it's not the final version)
from vim-go.
I'm really not angry, pardon if I sounded so... as you may see, I myself was once in the same trap.
from vim-go.
I'll check if it works, regarding "that's their business", what I think is that people should be aware of the behavior while it's not fixed, through a notice or documentation. Even more because it's ON by default. I know what was happening when I was editing my files (because of previous knowledge in these matters), but other people may end up having to figure out what is happening with their editor.
from vim-go.
Yes, but it can be disabled, it has settings, the source code is open. There are so many options. If you don't want to use autofmt just disable it :)
let g:go_fmt_autosave = 0
Ever behavior in this plugin has also a disable settings which is intended solely for this purpose, to give users the choice to do what they want.
from vim-go.
What I'm trying to say is that, I woudn't go for disabling this if there wasn't this issue, and if I had already known upfront there was such an issue, I wouldn't even let it enabled. Anyway... I think I'm done, it sounds like you is mad not me. What I said is just the truth, knowledge of an issue may be useful for the user to make the choice of enabling it or not, instead of figuring it out, even more because I think I have seen some statements regarding the plugin not messing with undo history.
from vim-go.
I'm not mad. I'm trying to solve this problem, that's it. Did you try the branch? If yes we can fix it from there.
from vim-go.
Yes, it looks like it solves the issue, the solution seems like the more recent and second most upvoted answer on SO, which I suggested as the chosen answer if it worked out better than my approach.
from vim-go.
The current master is the same as in SO's second answer :/ There is no difference, just I also display the error results.
from vim-go.
@fatih ah, ok then, my bad...
from vim-go.
The experimental branch unfortunately is losing the cursor position.
from vim-go.
I didn't notice where that happens yet. Maybe this is unsolvable in Vim (I have given up autofmt before because I felt the same).
from vim-go.
To reproduce it do 4-5 changes and then only undos. You will see that the cursor will jump to the beginning of the file.
from vim-go.
ah ok, in truth I could reproduce this with just one change that would actually produce reformatting when saving, like a single extra space before some closing parentheses.
from vim-go.
It would be great to see a fix land for this. Thanks for the plugin.
from vim-go.
@oblitum @clutchski could you please the fmt
branch https://github.com/fatih/vim-go/tree/fmt ? It has some changes that I believe fixes the problem but I'm still working on that. This is a Vim problem that is not easily solvable unfortunately.
from vim-go.
@fatih I'm not catching gaps in undo history as before yet, but the cursor still jumps to top of file when undoing/redoing.
from vim-go.
@oblitum that's not the case for me anymore. Wonder if something is causing this.
from vim-go.
Opening a file with this content:
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello" )
}
and issuing :w
will cause the space after "Hello"
to vanish, if you do undo after :w
you go to top of file. This would also happens if I had a longer editing history.
from vim-go.
But you are creating a new file without any undo history. It's normal that it goes to the top. If you do the same, and change to Hello
to Rello
, if you do now undo it will not go to the top. Instead it will jump to H
.
from vim-go.
@fatih As I said, this also happens if I had a longer editing history. Just edit the file, maybe changing the message, save it with :w
, then add that extra space, save it, it will get fixed, now undo, you go back and forth from the top of the file.
from vim-go.
in sum, this inserts jumps to top of file in undo history when there's any refomatting on saving.
from vim-go.
Ok can you to pull again and try? Seems I was missing a line from the master that was not removing the undo point causing via bufwritepre.
from vim-go.
You can follow the commits from this PR btw: #150
from vim-go.
@fatih it seems to be working nice now, I can't find issues at the moment.
from vim-go.
ops, it's not in master yet but I've closed the issue.
from vim-go.
That's an awesome news! After nearly 4 months seems it's beeing fixed. Yes it's not in master but going to merge sooin. I would be happy if you could use it 1-2 days and let's merge that branch than. Thanks for the valuable feedback @oblitum .
from vim-go.
@fatih ok no problem but sadly I'm not writting much Go lately so I won't be able to give feedback because I would be coding in Go because I'm not :-/
from vim-go.
Ok nevermind :) I have announced it on twitter and I'm also testing it heavily.
from vim-go.
I am facing similar problem with vim-prettier
used similar fixed as this to solve the “undo” but the “redo”from an undo of formatted coded still takes cursor to the top.
Does this behaviour also occurs here too ?
from vim-go.
@mitermayer vim-go is one of the few plugins that got this right (the only one at the time), even though I don't use it anymore, I tested it extensively, and reported it as a model for many other plugins that had the same issue. Not sure whether it's rock solid as before, but fatih came up with a solution after a good time of fiddling.
from vim-go.
@mitermayer vim-go does not suffer from that problem. The code hasn't changed much since the solution that @oblitum mentions. You can find the code that deals with undo in https://github.com/fatih/vim-go/blob/master/autoload/go/fmt.vim
from vim-go.
Related Issues (20)
- vim-go: Please comment on https://...537 if this impacts your workflow. HOT 4
- unknown directive: toolchain HOT 8
- Lua module not found for config of vim-go. Please use a `config()` function instead HOT 1
- Vim-Go not working on Raspberry Pi HOT 19
- Package metadata not found for file HOT 8
- debugger stops in assembler code file HOT 9
- Using code completion breaks navigation for arguments placeholders HOT 6
- mingw: GoDef (and various other commands) don't work, potentially due to pathing issue HOT 7
- Vim jumps to end of file on save HOT 2
- GoSameIds end position miscalculated for identifiers at the end of line
- GoExtract sends incorrect location to LSP HOT 1
- Error detected while processing Buf WritePre HOT 1
- Error detected while processing function <SNR>129_debugasync: E117 Unknown function: state ... HOT 1
- Typecheck errors when calling a function in another go file in the same package. HOT 9
- Godef has been Invalid in code with "import C" HOT 4
- Merged #3617 breaks UltiSnips placeholder mechanism HOT 3
- Cannot install or make it work with NeoVim gives error E492: Not an editor command :GoDef HOT 2
- Auto imports not working HOT 1
- Error in identifier/syntax prevents autocommands to be executed HOT 7
- Support quoting arguments to :GoImpl HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-go.