Code Monkey home page Code Monkey logo

Comments (7)

farmergreg avatar farmergreg commented on May 22, 2024 2

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.

farmergreg avatar farmergreg commented on May 22, 2024 1

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.

natecraddock avatar natecraddock commented on May 22, 2024

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.

nzbart avatar nzbart commented on May 22, 2024

@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.

natecraddock avatar natecraddock commented on May 22, 2024

@nzbart Sorry for the ambiguity. I found two solutions:

  1. 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.

  2. 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.

musjj avatar musjj commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.