Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Files while in GFiles mode #1181

Closed
5 tasks done
nrocco opened this issue Nov 17, 2020 · 2 comments
Closed
5 tasks done

Switch to Files while in GFiles mode #1181

nrocco opened this issue Nov 17, 2020 · 2 comments

Comments

@nrocco
Copy link

nrocco commented Nov 17, 2020

First of all, thank you for this vim plugin, it is awesome!

Current Situation

  • I have 2 key bindings
    • one that maps to Files and
    • another one that maps to GFiles.
  • 90% of the time I use GFiles to quickly find and open a file I am looking for.
  • Sometimes the file I am looking for is not in version control, but I used GFiles so there is no match.
  • I hit esc
  • Use my key binding to open Files and search again.

Desired situation

  • For those 10% of cases
  • I open GFiles, search for a file that is not under version control.
  • GFiles show no matches
  • I hit some magic key while in GFiles mode to switch to Files mode, while retaining the current search
  • More results show up and I open the file I wanted to open

This way one can make a habit of always using GFiles, which is fast, and fallback to Files only if needed.

Is it possible to configure fzf.vim this way?

@strimmlarn
Copy link

strimmlarn commented Nov 17, 2020

I used this line from this thread on reddit for exactly that, it stopped working 30 mins ago though. that why I'm lurking here right now. But I have a feeling its my fault. So maybe it works for you.

map <expr> <C-p> fugitive#head() != '' ? ':GFiles --cached --others --exclude-standard<CR>' : ':Files<CR>'

@nrocco
Copy link
Author

nrocco commented Nov 28, 2020

After reading https://github.com/junegunn/fzf#2-switch-between-sources-by-pressing-ctrl-d-or-ctrl-f and junegunn/fzf#1750

I have found a solution that works very well. I have defined these two environment variables

export FZF_DEFAULT_COMMAND='fd --type file --follow --hidden'
export FZF_DEFAULT_OPTS="--bind 'ctrl-f:reload($FZF_DEFAULT_COMMAND --no-ignore-vcs),ctrl-g:reload($FZF_DEFAULT_COMMAND)'"

In my .vimrc I have the following mapping:

nnoremap <leader>f :Files<CR>

Whenever I am working on a project

  • I bring up fzf in vim by pressing <leader>f
  • I search for some class, for example NotesController
  • The file happens to not be part of the git repository but part of a 3rd party module
  • I press ctrl+f while fzf is still open
  • fzf switches to fd in --no-ignore-vcs mode which now includes all files in the current directory
  • NotesController now appears in the list and I can edit it

I will close this issue.

@nrocco nrocco closed this as completed Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants