vis: global marks, do not reopen already opened file, fzf search current file

This commit is contained in:
2025-09-10 10:33:22 +02:00
parent 6757fc6aec
commit 78d758b8fb

View File

@@ -48,7 +48,9 @@ local function open_file_pos(line, open_cmd)
local file = iter() local file = iter()
local line_num = nil_or_tonumber(iter()) local line_num = nil_or_tonumber(iter())
local col = nil_or_tonumber(iter()) or 1 local col = nil_or_tonumber(iter()) or 1
open_file(file, open_cmd) if open_cmd ~= 'e' or vis.win.file ~= file then
open_file(file, open_cmd)
end
if line_num ~= nil then if line_num ~= nil then
vis.win.selection:to(line_num, col) vis.win.selection:to(line_num, col)
end end
@@ -120,6 +122,30 @@ local function fzf_reload(cmd)
' --bind "alt-enter:unbind(change,alt-enter)+change-prompt(2. fzf> )+enable-search+clear-query"' ' --bind "alt-enter:unbind(change,alt-enter)+change-prompt(2. fzf> )+enable-search+clear-query"'
end end
local function add_global_mark()
local file = vis.win.file.path
if file ~= nil then
local code, out, err = vis:pipe('vis-menu -p "global mark comment:"', true)
if code == 0 then
local prefix = file .. ':' .. vis.win.selection.line .. ':' .. vis.win.selection.col .. ': '
local line = vis.win.file.lines[vis.win.selection.line]
out = out:gsub('\n$', '')
if out ~= '' then
prefix = prefix .. '(' .. out .. '): '
end
out = io.open(os.getenv('HOME') .. '/.config/vis/global-marks.txt', 'a')
out:write(prefix .. line .. '\n')
out:close()
elseif err ~= nil then
vis:info(err)
elseif code ~= 0 then
vis:info('Program exit code ' .. code)
end
else
vis:info('Save file first')
end
end
local ripgrep = 'rg --column --line-number --color=always --smart-case' local ripgrep = 'rg --column --line-number --color=always --smart-case'
vis.events.subscribe(vis.events.INIT, function() vis.events.subscribe(vis.events.INIT, function()
@@ -154,6 +180,10 @@ vis.events.subscribe(vis.events.INIT, function()
search(fzf_reload(ripgrep .. ' -.')) search(fzf_reload(ripgrep .. ' -.'))
end, 'fzf: rg with hidden files') end, 'fzf: rg with hidden files')
vis:map(vis.modes.NORMAL, ' /', function()
search(fzf_reload(ripgrep .. ' --with-filename {q} ' .. escape_and_quoted(vis.win.file.path)))
end, 'fzf: rg current file')
vis:map(vis.modes.NORMAL, ' ff', function() vis:map(vis.modes.NORMAL, ' ff', function()
search('fd --type f | fzf') search('fd --type f | fzf')
end, 'fzf: files') end, 'fzf: files')
@@ -236,6 +266,16 @@ vis.events.subscribe(vis.events.INIT, function()
vis:command('!yazi') vis:command('!yazi')
end end
end, 'yazi in file directory') end, 'yazi in file directory')
vis:map(vis.modes.NORMAL, ' ma', add_global_mark, 'global marks: add')
vis:map(vis.modes.NORMAL, ' mj', function()
search('cat ~/.config/vis/global-marks.txt | fzf --tac')
end, 'global marks: jump')
vis:map(vis.modes.NORMAL, ' me', function()
vis:command('o ~/.config/vis/global-marks.txt')
end, 'global marks: edit')
end) end)
vis.events.subscribe(vis.events.WIN_OPEN, function(win) vis.events.subscribe(vis.events.WIN_OPEN, function(win)