-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cursor position not maintained after undo #8
Comments
Thank you for your report, @bear24rw. Actually, I've already noticed this issue but I don't know a way to fix. I still investigate the way. |
It seems that undo information moves cursor. I've found |
I investigated the way not to move a cursor at undo but I couldn't... I'll remain this issue open. If anyone knows how to fix this issue, please let me know with a comment. |
This feature has some side effects. So you should be careful if you introduce this feature. - Sometime, screen is moved on auto-formatting. - Cursor position history is changed (Issue #8)
+1 vim-go plugin got it solve here: fatih/vim-go#40 |
after much struggle... by the way. |
Oh, it sounds great! I'll check the issue later. Thank you for the information. |
I don't know exactly which ones fixes all the problems. He told me to track pull request 150 at the time. The first one you refer to seems to be the most relevant. |
OK, thanks. I'll check commits in the pull request. |
indeed. |
…do (issue #8) Replace current buffer with workaround not to move the cursor on undo (issue #8) The points are: - Do not touch the first line. - Use :put (p, P and :put! is not available). To meet above condition: - Delete all lines except for the first line. - Put formatted text except for the first line.
@rhysd hi, I'm just looking around, and your last commits suffer from the side-effect mentioned at the beginning of fatih/vim-go#40. You can just follow the procedure I mention there using a C++ file, the same thing will happen. |
@oblitum |
@rhysd I'm wondering whether you have stumbled upon an issue vim-go author has gone through while he asked me to test his solution. He had issues with BufWritePre, which can be checked from this comment. If you look at the changes applied, you can see he documents the issue regarding BufWritePre. |
Anyway, if my comment can't help, my opinion is that, having an extra undo point is less worse than missing one. |
Check out this file: https://github.com/fatih/vim-go/blob/master/autoload/go/fmt.vim#L44 All the functionality is there and I've tried to write many comments for each step so it can be followed. |
@rhysd yes, it's currently moving to the top. |
thanks... I didn't notice the comment close this issue. |
I have found a temporary solution. It might be of help to others, until this issue is fixed. I have put the following in my .vimrc (init.vim) file. This save the cursor position and scroll position, before undo / redo, then restores it after calling the builtin undo / redo command. function! s:safeundo()
let s:pos = getpos( '. ')
let s:view = winsaveview()
undo
call setpos( '.', s:pos )
call winrestview( s:view )
endfunc
function! s:saferedo()
let s:pos = getpos( '.' )
let s:view = winsaveview()
redo
call setpos( '.', s:pos )
call winrestview( s:view )
endfunc
nnoremap u : SafeUndo <CR>
nnoremap <C-u> : SafeRedo <CR> I am a vimscript novice, so please feel free to critique. |
I believe this problem is also causing my marks to be cleared |
@jmnel I got "not an editor command" error when trying to undo with key "u", after adding your script to my .vimrc. Does it work for you? |
To replicate:
shift+v
to visually select a line,cf
to run clang format (cursor is in correct position)u
to undo (cursor is now at top of file)Is there a way to have the cursor remain in the original position after the undo?
clang-format version 3.4
The text was updated successfully, but these errors were encountered: