goto-preview
goto-preview copied to clipboard
[FEATURE]: Toggle single preview window and show definition automatically when cursor moving in source window.
Is your feature request related to a problem? Please describe. When reading the code of a completely new project, it is convenient to keep the 'Definition preview' toggled and jump along with the cursor moving in the source code window, in particular with a wide screen which is spacious to have the source window in the left and the preview window in the right.
Invoke/Close 'Goto definition' manually is a bit time-consuming in the case, it will be nice to have an option to enable this feature.
Describe the solution you'd like Using a single preview window and toggle it, jump to definition automatically by tracing the cursor moving events in the source window.
Describe alternatives you've considered 'srcexpl' in vim plugin, or manually open/close the preview window with shortcuts in neovim.
https://github.com/wenlongche/SrcExpl.git
Additional context N/A
Hey, it's an interesting idea. Though if the feature is built it should be easily disabled since it can fairly easily get in the way.
Until then, you can setup something yourself.
Somewhere in your lua config:
local group = vim.api.nvim_create_augroup("constant_peek", {})
vim.api.nvim_create_autocmd("CursorHold", {
pattern = { "*.*" },
group = group,
callback = function()
require("goto-preview").goto_preview_definition {
focus_on_open = false,
dismiss_on_move = true,
}
end,
})
Ronnie, It is pretty cool and what I am looking for in general. It will be nice if:
- Toggle the preview window as a split window to replace a popup one.
- With an 'Enter' key event in preview window to go to the definition in the main editor buffer.
Can you help to get the magic? :) Thank you very much!
Hey
- You can just use normal vim window movements: https://github.com/rmagatti/goto-preview#window-manipulation
- I'm not sure what you mean on this one
Hi,
- I tried to move the preview window to the right, but when I move back to the source buf and a new preview window pops up afterwards. Anyway to show one preview window? I have disabled 'stack' option but it didn't work.
- I guess it will work if #1 fixed, so it is ok for now.
My options:
require("goto-preview").setup {
width = 120; -- Width of the floating window
height = 60; -- Height of the floating window
border = {"↖", "─" ,"┐", "│", "┘", "─", "└", "│"}; -- Border characters of the floating window
default_mappings = true; -- Bind default mappings
debug = false; -- Print debug information
opacity = nil; -- 0-100 opacity level of the floating window where 100 is fully transparent.
resizing_mappings = true; -- Binds arrow keys to resizing the floating window.
post_open_hook = function(bufr)
jump_func(bufr)
end,
post_close_hook = nil; -- A function taking two arguments, a buffer and a window to be ran as a hook.
references = { -- Configure the telescope UI for slowing the references cycling window.
telescope = require("telescope.themes").get_dropdown({ hide_preview = false })
};
-- These two configs can also be passed down to the goto-preview definition and implementation calls for one off "peak" functionality.
focus_on_open = true; -- Focus the floating window when opening it.
dismiss_on_move = false; -- Dismiss the floating window when moving the cursor.
force_close = true, -- passed into vim.api.nvim_win_close's second argument. See :h nvim_win_close
bufhidden = "wipe", -- the bufhidden option to set on the floating window. See :h bufhidden
stack_floating_preview_windows = false, -- Whether to nest floating windows
preview_window_title = { enable = true, position = "left" }, -- Whether to set the preview window title as the filename
}
Screenshots:
-
preview window to right
-
New preview window pops up.
Hey @weiyshay would you mind recording a video? I'm still not sure I get what issue you're running into or what exactly you're trying to accomplish