Feature: use mkview with builtin previewer
Have you RTFM'd?
- [x] I have done proper research
Feature Request
as it is right now, "builtin" will preview the file at the beginning.
I use mkview as a plugin to restore a file's previous view/open it at the last location.
I would like to ask that "builtin" preview would use :loadview if file has a previous :mkview
I am willing to implement this if maintainers are to accept this feature
The way I see it this is only relevant for pickers without line/col, i.e. only files, git-files, oldfiles, args, etc.
Does it have to be an existing view? We can also restore the last known location of the file using marks, this is what I use in my autocmds for BufReadPost:
callback = function(e)
local mark = vim.api.nvim_buf_get_mark(e.buf, '"')
local line_count = vim.api.nvim_buf_line_count(e.buf)
if mark[1] > 0 and mark[1] <= line_count then
vim.cmd 'normal! g`"zz'
end
end,
The way I see it this is only relevant for pickers without line/col, i.e. only files, git-files, oldfiles, args, etc.
yes
Does it have to be an existing view? We can also restore the last known location of the file using marks ...
Doesn't have to be an existing view, but maybe some means to position the view? like a part of a config
preview_center=
---@param buf integer
---@return {line:integer, col:integer}|false
function(bufnr) end
I’ve given it more thought, I don’t think this is worth the effort, all buffer types have the current line previewed, LSP, grep, tags, all show the corresponding line in the preview so this remains relevant only for files, git_files, oldfiles, etc.
While this could be nice this is very niche, especially since if you already use this functionality you’re just one enter away from getting into the last location, on top of that some users will find it confusing why is the file scrolled and I’ll have to explain why is that or provide yet another obscure option to turn this off or on.
Bottom line, I don’t think is worth it, closing as not planned.
Btw if you want to implement this yourself you can extend the builtin previewer as explained here: https://github.com/ibhagwan/fzf-lua/wiki/Advanced#preview-nvim-builtin
You can override preview_buf_post, call the original method and add your code on top:
https://github.com/ibhagwan/fzf-lua/blob/3d4342120cf12f36b60a8161a8835b111ec5ec9a/lua/fzf-lua/previewer/builtin.lua#L1280
Then set your custom previewer as the new default.
hey, I did a command to output grep-ish lines (/path/to/file:line:col:text)
But I cannot use it with require "fzf-lua".grep(...) because it expects "grep", "rg"... as the command name. any pointers on this?
hey, I did a command to output grep-ish lines (
/path/to/file:line:col:text)But I cannot use it with
require "fzf-lua".grep(...)because it expects"grep","rg"... as the command name. any pointers on this?
Can't you use a custom cmd with :lua FzfLua.grep({cmd = ... }) (can also use raw_cmd to avoid any transformation of the command args).
I tried both cmd and raw_cmd but I'm getting the following error:
5108: Error executing lua: ...l/share/nvim/lazy/fzf-lua/lua/fzf-lua/providers/grep.lua:49: attempt to call method
'match' (a nil value)
stack traceback:
...l/share/nvim/lazy/fzf-lua/lua/fzf-lua/providers/grep.lua:49: in function 'get_grep_cmd'
...l/share/nvim/lazy/fzf-lua/lua/fzf-lua/providers/grep.lua:198: in function 'grep'
/home/user/.config/nvim/init.lua:96: in function </home/user/.config/nvim/init.lua:86>
I tried both
cmdandraw_cmdbut I'm getting the following error:5108: Error executing lua: ...l/share/nvim/lazy/fzf-lua/lua/fzf-lua/providers/grep.lua:49: attempt to call method 'match' (a nil value) stack traceback: ...l/share/nvim/lazy/fzf-lua/lua/fzf-lua/providers/grep.lua:49: in function 'get_grep_cmd' ...l/share/nvim/lazy/fzf-lua/lua/fzf-lua/providers/grep.lua:198: in function 'grep' /home/user/.config/nvim/init.lua:96: in function </home/user/.config/nvim/init.lua:86>
Can you post what you’re trying to do and the code you’re trying to run?
You can also use fzf_exec API directly with a previewer to run whatever you want.
the problem can be reproduced, at least in a linux distro, with the following:
lua require'fzf-lua'.grep{cmd={'printf', '%s\n', '/home/user/a/file.txt:1:1:text', '/home/user/other/file.txt:1:1:textt'}, search='noop'}
Use string command (not table)
the problem can be reproduced, at least in a linux distro, with the following:
lua require'fzf-lua'.grep{cmd={'printf', '%s\n', '/home/user/a/file.txt:1:1:text', '/home/user/other/file.txt:1:1:textt'}, search='noop'}
Not sure what you’re trying to do here but use raw_cmd=“…” as string, not table and it will work.