Skip to content
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

feature request: auto-refresh preview on cursor move #42

Closed
1 task done
yingzhu146 opened this issue Jan 19, 2023 · 3 comments
Closed
1 task done

feature request: auto-refresh preview on cursor move #42

yingzhu146 opened this issue Jan 19, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@yingzhu146
Copy link

yingzhu146 commented Jan 19, 2023

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

I'd love to have a mode where the preview refreshes automatically on CursorMove (including refreshing/staying active, after cd'ing to new dir)

A non-working autocmd-based solution that I've tried but then realized that this won't work since autocmds don't have a ft property so not sure how to get it to restrict to the oil window

      vim.api.nvim_create_user_command("OilPreviewEnable", function()
        require("oil").select({ preview = true }) -- preview current right away
        vim.api.nvim_create_autocmd({ "CursorMoved" }, {
          ft = "oil",
          callback = function()
            require("oil").select({ preview = true })
          end,
        })
      end, { nargs = "*", desc = "Enalbe Oil Preview Mode " })
    end,

But I hope this conveys the idea. In MacOS finder you can ctrl-space to start a preview and c-n, c-p, and then ESC to stop preview - would be cool to be able to do the same here via oil specific <esc> and <c-space> mappings for turning on/off the live preview

Provide background

Very similar in spirit to #41 - trying to improve speed at which I can explore novel repos

Additional details

No response

@yingzhu146 yingzhu146 added the enhancement New feature or request label Jan 19, 2023
@star-szr
Copy link

This is not exactly the answer, but you could take a look at (and build upon) https://github.com/stevearc/oil.nvim/discussions/39 to at least get closer.

@stevearc
Copy link
Owner

stevearc commented Jan 22, 2023

I added this as the default behavior. If anyone finds the auto-update behavior intrusive, put in a request and I'll add a config option to disable it.

Just for your education, the way you could do this yourself is by creating a FileType autocmd that runs on oil buffers, and then inside of that create a buffer-local CursorMoved autocmd.

@yingzhu146
Copy link
Author

yingzhu146 commented Jan 23, 2023

This is amazing, just made my day. Such a great convenience.

Also really appreciate the explanation, really kind of you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants