Closed pabsan-0 closed 3 months ago
sink
function, there's no need to use fzf#vim#grep
. The basic fzf#run
is a better fit here.
alt-enter
--expect=alt-enter
to make fzf print it as the first line when you press it. If you press enter, the first line will be an empty line.sink*
instead of sink
.transform
action bound to focus
event. This will however, make the cursor movement a little bit slower because fzf will constantly run a shell command.let s:snippets_path = "~/snippets/"
function! s:rg_file_read(lines)
if len(a:lines) < 2
return
endif
let [key, file] = a:lines
if key == 'alt-enter'
execute 'tabedit' s:snippets_path .. file
else
execute 'read ' .. s:snippets_path .. file
endif
endfunction
command! -bang -nargs=* CustomSnippets
\ call fzf#run(fzf#vim#with_preview(fzf#wrap({
\ 'source': "rg -m 1 -L --no-heading --pretty --smart-case ".shellescape(<q-args>),
\ 'options': ['--reverse', '--ansi', '--expect=alt-enter', '--bind', 'focus:transform:[[ -n {} ]] && [[ ! {} =~ : ]] && exit; [[ $FZF_ACTION =~ up$ ]] && echo up || echo down'],
\ 'dir': s:snippets_path,
\ 'sink*': function('s:rg_file_read')
\ }), <bang>0))
man fzf
)Hi, I want different actions to be performed with Enter and ShiftEnter.
I'm using fzf to fuzzyfind snippets and would like Enter to copy snippets into my current file and ShiftEnter to edit them. This is what my vimrc lines look like:
From
man fzf
the alternate action could be done on the CLI via something likefzf --bind "enter:execute(less {})"
, but I can't figure how to port that into vim. Could you please provide some pointers?