Giter Club home page Giter Club logo

Comments (10)

rmagatti avatar rmagatti commented on August 22, 2024 1

Ah I see what you mean. That depends if your preview ends up opening the same buffer or not, if it doesn't you wouldn't have the issue you're seeing. Since the mapping is unaware of anything goto-preview related when it is already in place, since it is the same buffer you'll end up having the mapping still unfortunately.

from goto-preview.

benallan avatar benallan commented on August 22, 2024 1

Thanks for opening the neovim issue, it would definitely be nice to have a way to limit the scope of mappings to just one window, especially now that we have more floating windows.

from goto-preview.

rmagatti avatar rmagatti commented on August 22, 2024

@sahilsehwag hey, you can already do that by just normally closing :q the window if you have it focused.

But the idea is interesting for when you don't have the preview float focused anymore, I'll give it some thought.

Thanks for the submission!

from goto-preview.

serhez avatar serhez commented on August 22, 2024

@rmagatti could it be possible to close the preview window by just hitting 'q', as in other plugins (e.g., lspsaga)?

from goto-preview.

rmagatti avatar rmagatti commented on August 22, 2024

@serhez well, yes. But that's not something I would want to add as a default or anything like that. I like the fact that these preview windows are just normal windows that you can do anything with, rebinding q would mean not being able to record a macro in them anymore, which might be what you want ofc but not something I'd want to make the plugin decide for you.

That said in response to this I created this PR #15 which should enable you to set whatever mappings you'd like on a float preview window. Hope that does it for you.

from goto-preview.

serhez avatar serhez commented on August 22, 2024

@rmagatti #15 looks good, thanks! Agreed that it is a nice option but may not necessarily be a default. Cheers!

from goto-preview.

rmagatti avatar rmagatti commented on August 22, 2024

@serhez this is an example config for doing what you want, i.e closing the preview window with q.

require('goto-preview').setup {
  post_open_hook = function()
    vim.cmd[[nnoremap <buffer> q :q<CR>]]
  end
}

from goto-preview.

benallan avatar benallan commented on August 22, 2024

In case this helps anyone else: I wanted the close mapping to only apply to the preview window; the example above will mean that q will continue to be mapped to close the window/vim in that buffer, which I didn't want. I can't see any nice way to limit the mapping to just the goto preview window, so I'm using this hack where the mapping disables itself after closing the window:

require('goto-preview').setup {
  post_open_hook = function()
    vim.cmd [[nnoremap <buffer> gq <c-w>c :unmap <buffer> gq<CR>]]
  end
}

from goto-preview.

rmagatti avatar rmagatti commented on August 22, 2024

Actually @benallan with how the hooks are being triggered now, I do check if the window is a preview window and only then call the hook function, that hook function, because it's causing nnoremap <buffer> q :q<CR> the <buffer> means it's buffer local, so it'll only apply to the preview window's buffer, so my example should work exactly the way you would expect.

from goto-preview.

benallan avatar benallan commented on August 22, 2024

it's buffer local, so it'll only apply to the preview window's buffer, so my example should work exactly the way you would expect.

I'm probably misunderstanding something, but when I use goto preview on a function which is defined in the same file, the preview window appears so I now have two windows, but it's the same buffer displayed in both windows. So the buffer local mapping will persist after the preview window is closed, and it definitely seems to when I test it. Is that not the case for you?

Or when the preview window is opened, is it supposed to use a different buffer to the one that was already open?

from goto-preview.

Related Issues (20)

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.