Comments (7)
Thank-you for the patch @natecraddock and @nzbart. Merged into mainline for testing.
Everyone, please test it out and leave comments here if you find something this patch breaks.
@oblitum would you be willing to re-test the fold feature and ensure it continues to work properly?
from vim-lastplace.
Hi Nathan, thanks for the truly excellent bug report.
I won't have availability to tackle this for quite some time.
If you or anyone else wants to work up a patch and submit it, I'd be more than happy to review it and pull it in to the mainline.
from vim-lastplace.
I looked a bit more into this, and I can confirm that this bug also occurs in vim, not just neovim.
Neovim's docs suggest using the following for restoring the cursor position automatically:
autocmd BufRead * autocmd FileType <buffer> ++once
\ if &ft !~# 'commit\|rebase' && line("'\"") > 1 && line("'\"") <= line("$") | exe 'normal! g`"' | endif
This is different from the suggested command for vim because of differences in how neovim handles filetype loading: neovim/neovim#16339
I tried the above in neovim and I don't see the bug anymore.
vim-lastplace uses a BufWinEnter
autocmd. Out of curiosity I replaced the BufWinEnter
with BufRead
in vim-lastplace and I cannot replicate this issue in either vim or neovim. Everything else seems to work okay still, though I did not test extensively. For example, I don't use folds and I didn't test if this impacted folds.
I'm not super familiar with the differences between BufWinEnter
and BufRead
, but that simple change seems to have resolved things.
from vim-lastplace.
@natecraddock thanks for posting a solution. To clarify, do you remove farmergreg/vim-lastplace and replace it with the code in your comment, or do you load this plugin in addition to the autocmd?
from vim-lastplace.
@nzbart Sorry for the ambiguity. I found two solutions:
-
Remove the plugin and use the above autocommand in neovim. This removes the bug, but this autocmd is missing a few features of lastplace (like centering the cursor). Vim has a similar autocmd documented at
:h restore-cursor
. -
Make the following edit to lastplace
diff --git a/plugin/vim-lastplace.vim b/plugin/vim-lastplace.vim
index 1aacd16..6ed1bec 100644
--- a/plugin/vim-lastplace.vim
+++ b/plugin/vim-lastplace.vim
@@ -76,5 +76,5 @@ endf
augroup lastplace_plugin
autocmd!
- autocmd BufWinEnter * call s:lastplace()
+ autocmd BufRead * call s:lastplace()
augroup END
As I mentioned above, I'm not sure if solution 2 causes any side-effects, but it seems to work perfectly for me!
from vim-lastplace.
Converted the autocmd from the docs to lua:
vim.api.nvim_create_autocmd("BufRead", {
callback = function(opts)
vim.api.nvim_create_autocmd("FileType", {
once = true,
buffer = opts.buf,
callback = function()
local ft = vim.bo[opts.buf].ft
local last_pos = vim.api.nvim_buf_get_mark(opts.buf, '"')
if
not (ft:match("commit") and ft:match("rebase"))
and last_pos[1] > 1
and last_pos[1] <= vim.api.nvim_buf_line_count(opts.buf)
then
vim.api.nvim_feedkeys('g`"', "x", false)
end
end,
})
end,
})
Not really that familiar with vimscript, so feel free to point out any mistakes.
from vim-lastplace.
Related Issues (19)
- Debian Package HOT 1
- Option for opening folds if the last edited area is inside a closed fold HOT 6
- Keep horizontal position HOT 3
- doesn't play well with NERDTree and TagBar HOT 2
- vim-lastplace does not work with templates HOT 2
- vim-lastplace conflicts with vim-buffergator HOT 3
- Keep windows position? HOT 1
- global disable or add check for vimdiff HOT 2
- Last place centering HOT 3
- vim-lastplace can not work well with latest vim HOT 1
- let g:lastplace_open_folds = 0 still opens fold after reopening file HOT 5
- Plugin automatically expands folded text HOT 1
- Save lastplace_ignore and lastplace_ignore_buftype as list instead of string HOT 1
- Add note about `:h last-position-jump`, available out-of-the-box in recent versions of Vim HOT 1
- `g:lastplace_open_folds` doesn't work when `foldmethod` is set in modeline HOT 1
- Compare to vim-stay HOT 3
- vim-lastplace scrolls the file by one line from top HOT 7
- Maintain Scroll Position HOT 1
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-lastplace.