junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
65.41k stars 2.41k forks source link

Keep fzf window open after selecting a file #2213

Closed ghost closed 4 years ago

ghost commented 4 years ago

Info

Is it posssible to keep the fzf window open after selecting a file? I've got a script that opens a chosen file in it's defalt program, and it's annoying run fzf over and over again after opeing the first file.

rayiik commented 4 years ago

Do you mean like a resume? If you mean like open file and when you close the file your back I. The same fzf search? If so yes just don’t open the file using return use the —bind=“key:execute:vim/emacs/nano {}” or whatever command your opening with should work i use it when nvim okular display man bg if you just want to throw it to a background process which you can then call with fg In some cases you may need to have your execute command echo {} | xargs othercmd but very doable if I understood your question

ghost commented 4 years ago

I've switched to using this from the wiki, but when I press control+o, it opens the file and fzf quits

fo() {
  IFS=$'\n' out=("$(fzf-tmux --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)")
  key=$(head -1 <<< "$out")
  file=$(head -2 <<< "$out" | tail -1)
  if [ -n "$file" ]; then
    [ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file"
  fi
}
rayiik commented 4 years ago

Hey so this is my .fzfrc which I source from my init file

#!/bin/bash
export FZF_MOVEMENT="--bind='ctrl-s:preview-page-down' \
    --bind='ctrl-a:preview-page-up' \
    --bind='ctrl-u:half-page-up+refresh-preview' \
    --bind='alt-u:page-up+refresh-preview' \
    --bind='ctrl-d:half-page-down+refresh-preview' \
    --bind='alt-d:page-down+refresh-preview' \
  --bind='alt-y:yank' \
  --bind='ctrl-y:kill-line' \
  --bind='alt-g:ignore' \
  --bind='ctrl-g:top' \
    --bind='alt-a:toggle-all' \
  --bind='alt-s:toggle-sort' \
  --bind='alt-h:backward-char+refresh-preview' \
  --bind='alt-l:forward-char+refresh-preview' \
  --bind='ctrl-l:clear-screen'"
 export FZF_DEFAULT_COMMAND="rg -uu \
  --files \
  -H"
export FZF_ALT_COMMAND="fd -uu -t f"
export FZF_PREVIEW="nvimpager {}"
export FZF_DEFAULT_OPTS="$FZF_MOVEMENT \
    --bind='ctrl-h:execute(moreman {})' \
  --bind='ctrl-p:toggle-preview' \
  --bind='ctrl-v:execute(nvimpager {})' \
  --bind='f8:preview(nvimpager {})'
  --bind='f9:preview(moreman {} 2>/dev/null)' \
    --tiebreak='length,index' \
  --preview-window 'right:68:wrap'
  --height=100
    --exact \
    --info='inline' \
    --cycle \
  --reverse \
    --multi \
    --ansi"
if [[ -z "$DISPLAY" ]]; then
  FZF_DEFAULT_OPTS+="
--color=info:1 \
--color=prompt:2 \
--color=pointer:3 \
--color=hl+:4 \
--color=marker:6 \
--color=spinner:7 \
--color=header:8 \
--color=border:9 \
--color=hl:0 \
--color=preview-fg:11 \
--color=preview-bg:12 \
--color=fg:13 \
--color=fg+:14 \
--preview='${FZF_PREVIEW:+"cnat; $FZF_PREVIEW"}'";
    else
      source .fzfguirc
fi

And you can check out https://github.com/rayiik/Man-fzf-scripts specifically fzcom and coms both work the way your hoping but open man on Ctrl-h normally I’d try to build you something customised to your needs but I’m writhing both my CompTIA a+ exams this weekend + an exam for my college if unresolved after I’ll have a look at it but if you have any questions as to what some of my scripts do drop me a line and I’ll get back to you as soon as possible

junegunn commented 4 years ago

I've switched to using this from the wiki, but when I press control+o, it opens the file and fzf quits

That's how --expect was designed to work. I suggest you carefully go through the man page to learn more about the options. And as @rayiik suggested, execute binding is what you're looking for.