Giter Club home page Giter Club logo

vscode-fzf-quick-open's Introduction

Build Status Marketplace Installs Rating

fzf-based fuzzy searching in VScode to open files/folders and filter ripgrep results

Any time that vscode requires interaction with the OS file dialog, the workflow can become much less efficient. This comes up when opening files outside of your workspace folders or adding a workspace folder. This extension solves that by providing these actions using fzf.

Provides an interface to search using ripgrep and browse the results using fzf. This is inspired by Vim's rg and fzf integration. The search pattern defaults to the word under your cursor or your current selection and is easily overridden.

Works on *nix, Mac, and Windows. Tested with CMD, PowerShell, and Git Bash on Windows.

Usage

Provides the commands:

  • fzf: Search using rg and fzf to search using fzf and ripgrep
  • fzf: Open file using fzf opens a terminal in which you can choose a file
  • fzf: Add workspace folder using fzf to add a workspace folder

On terminal launch, the pwd is chosen based on the active editor file. Also adds

  • fzf: Search in PWD using rg and fzf
  • fzf: Open file in PWD using fzf
  • fzf: Add workspace folder from PWD using fzf

which are the same as above but switches to parent directory of active file on every invocation.

On terminal launch, the Project Root (.git) is opened based on the results of git rev-parse --show-toplevel on the active editor file. Also adds

  • fzf: Search in Project Root (.git) using rg and fzf
  • fzf: Open file in Project Root (.git) using fzf

which are the same as the above but switches to project root directory of the active file on every invocation.

Bind the commands to keyboard shortcuts to launch faster.

Configuration

Change the setting fzf-quick-open.initialWorkingDirectory to override the initial working directory used for the fzf terminal. Change fzf-quick-open.findDirectoriesCmd to change the command used to find directories. Something like fd --type d is very fast if you use fd.

By default fzf is used as the fuzzy matcher command. To change this to add flags or use another tool like skim (sk) modify the setting fzf-quick-open.fuzzyCmd to be the command that should be run. It will be plugged in to a context like: rg searchTerm | fzf --ansi --print0 ... and needs to support --ansi --print0 flags.

To change the rg case matching options use the setting fzf-quick-open.ripgrepSearchStyle to choose between:

  • Case sensitive
  • Ignore case
  • Smart case

To pass other flags to rg add them to fzf-quick-open.ripgrepOptions.

Setup

  1. Install fzf

  2. Install ripgrep

  3. For best performance you should set up fzf to use the amazingly fast fd

    ~/.config/fish/config.fish

    set --universal FZF_DEFAULT_COMMAND 'fd'

    ~/.bashrc

    echo "export FZF_DEFAULT_COMMAND='fd'" >> ~/.bashrc
  4. Configure the setting fzf-quick-open.findDirectoriesCmd to use fd: fd --type d

Examples

Search with ripgrep Search with rg and fzf

Open file Open file with fzf

Open workspace folder Add workspace folder with fzf

vscode-fzf-quick-open's People

Contributors

buzz-dee avatar chapmanjacobd avatar clearfeld avatar dependabot[bot] avatar inch4tk avatar kamholtz avatar ngrnxk avatar rlivings39 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vscode-fzf-quick-open's Issues

Search in project root

I know that there is an option to search in the project root when using with vim, where "project root" being found by the folder that has .git folder (basically the repo home upper most directory). Is there a possibility to add this here as well?

Currently if I search in a subfolder, then the search is only within that subfolder, not taking into account files in the project that are found in upper directories.

runFzfFile and runFzfAddWorkspaceFolder inherit previous working directory

If I run one of the commands that uses the current working directory, then the terminal used for fzf is changed to that directory, but runFzfFile and runFzfAddWorkspaceFolder run in the same terminal and don't reset the directory to the current workspace, meaning that runFzfFilePwd causes runFzfFile to have the same behaviour if it's run afterwards.

Wrapping the command in a subshell, such as (cd whatever/cwd/is; cmd) will ensure that the cwd is reset after each command, which is probably cleanest.

Add workspace folder fails on Mac

$ find -type d
find: illegal option -- t
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

Using fd works fine on Mac

Add folder doesn't work in remote ssh

The code command put on the path doesn't support -a.

$ fd --type d -I | fzf | xargs -r code -a                                                                                                               
Ignoring option a: not supported for code.
At least one file or folder must be provided.

Finding the extension on vscode

Thanks for the extension. Have couple of suggestions to make it easier to find the extension on vscode:

  1. Add fuzzy in title/tags/description.
  2. Highlight search more. This extension stands out for fuzzy keyword search. Native support for fuzzy file search is quite OK on vscode.

Is it possible to automatically close the terminal panel that runs fzf after completing or canceling a search session?

Hi,

Thanks for making such a useful extension!

I want to ask how I can make it automatically close the terminal panel that runs fzf after completing or canceling a search session?

Currently, when I cancel a search (by Esc) or visit a searched pattern (by Enter), the terminal panel that runs fzf still open.

FYI, I notice that in another extension https://github.com/tomrijndorp/vscode-finditfaster, it can automatically close the terminal when I press Esc or Enter.

Thank you!

Implement "open folder" command

Hi @rlivings39!
Very nice extension!

Could it be possible to implement the command "File: open folder..."?
I know that the extension already support "fzf: Add workspace folder using fzf...", but this is slightly different from simply opening the folder.
I'm no expert in TS and VSCode extension, but if you don't have time for that I will try to create a PR for this.

Thanks in advance!
Luca

No `fzf-quick-open` commands can be found.

I'm using latest VSCode on latest Windows 10.

Whenever I try to run a fzf-quick-open command, I get the following error:
image

I have all three of fd, rg, and fzf in my path, and I'm not sure what else I might have done wrong. Weirdly, the "feature contributions" tab of this extension on VSCode seems to indicate that several commands are added by this plugin, but I can't use any of them.

Maybe there is no need to "escapeWinPath"

I'm working on Windows. I found that using fzf: Open file using fzf the fzf runs well but when I selected the file, vscode dosen't open the file. Also, I got a error message said "The specified path is invalid." on cmd.

After reading the code, I tried the following operations on cmd:

C:\Users\my_username>echo open $$ F:\Path\To\Workspace $$ server\bin\start.bat > "\\?\pipe\fzf-pipe-21160"

C:\Users\my_username>echo open $$ F:\\Path\\To\\Workspace $$ server\bin\start.bat > "\\?\pipe\fzf-pipe-21160"

C:\Users\my_username>echo open $$ F:\\Path\\To\\Workspace $$ server\bin\start.bat > "\\\\?\\pipe\\fzf-pipe-21160"
The specified path is invalid.

C:\Users\my_username>

It shows that, the first 2 command did work and my vscode opened that start.bat, however, the 3rd one echos an error. But now
what the extension produces is like the 3rd one.

I tried modifying function escapeWinPath to make it just return origPath;, and it seems everything works well.

Is it truly necessary to use escapeWinPath on the named pipe and the path to scripts\topipe.bat ?


PS: I think this extension will really save my time! ๐Ÿ˜† vscode's Ctrl+P can be very slow when I'm working on a large project.

xargs: illegal option -- r

Open file using fzf

fzf --print0 | xargs -0 -r code
xargs: illegal option -- r
                          usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
                                [-L number] [-n number [-x]] [-P maxprocs] [-s size]
              [utility [argument ...]]
ProductName:	Mac OS X
ProductVersion:	10.15.3
BuildVersion:	19D76

Searching with rg finds multiple duplicate results

I have this weird behaviour that when I search for a term with rg with this extension I get multiple results that are basically the same, but somehow are separated by different column number of the cursor. See the screenshot provided.

In StudentController.java there is only one result for List<Student> at line 37, but it finds it multiple times - what's wrong? I do not pass any options to rg.

I identified the culprit:
The way I like to search is not through the input box that opens up, rather, I press enter without entering any terms, and then search in the interactive panel that opens up in the terminal inside vscode. If I search with the input box, this problem is not occurring. I also found out that that the default command of rg has --vimgrep which actually might cause this behaviour as described in the man rg docs. Is there something I can do to search the way I want and not through the input box?
Screen Shot 2021-07-31 at 14 08 28

`cut` on MacOS is not gnu coreutils

cut on MacOS X is rather more limited than gnu cut, and so cut -z is invalid, producing cut: illegal option -- z

If gcut is installed through brew install coreutils then that works as expected, and either OS detection in the extension or a configuration option for the name of the cut binary could be used. Inserting | tr '\n' '\0' to nul-terminate the string instead also works.

I'm happy to put a PR in, once I've heard if there's a strong preference one way or the other.

Windows Cmd Escape Path issues with new terminal profiles

Same error as in issue #23, now caused by using terminal profiles instead of the deprecated terminal.integrated.shell config.
The fix is straightforward, if the old term shell value is not set just query for the new default profile and check for cmd.exe there.

I will add a pull request.

Add RipGrep options

Hi, just started using and it's a great extension.

I miss being able to set ripgrep options. I have some generated files that are ignored by the default config and it would be nice to be able to set ripgrep flags to not ignore them.

custom shortcuts

Hello, I would like to replace the original "Cmd+P" shortcut like this in keybindings.json:

{
    "key": "cmd+p",
    "command": "fzf-quick-open.runFzfSearch"
  }

However, when I do this, it prompts me to enter a starting pattern or it copies the pattern in from under my cursor:
image

It would be cool to be able to go straight to fzf with no pre-entered text. Any idea?

does nearly work on windows

Hi

On windows, everything is looking fine: I have fzf and fd; they are working fine together. Until I actually select a file/dir. Then, all the backslashes seem to be quotation characters, thus leaving just one long string. The file/dir, of course, cannot be found by vscode.

Regards
Adam

Remove need for codeCmd setting

dd90b93 added a setting fzf-quick-open.codeCmd to handle using code-insiders for the command rather than code. We should be able to programmatically determine this.

For example someone saw that the path ~/.vscode-server-insiders/bin/1c36d747fbf113144d3bf82b0aa3cbd290714e38/bin/code-insiders gets set up with remote ssh. Can we find that and use it?

Weird default initial working directory

The initialWorkingDirectory gave me some weird results.
Looks like it sets to the folder where the last open file but I'm not sure.

For me, this setting worked best

"fzf-quick-open.initialWorkingDirectory": "${workspaceFolder}"

Accepting PR?

Hello, thanks for the extension.
We have some ideas to improve the workflow using the extension, just like the CTRL+P works.
I want to know if you are accepting PR or should we fork it and work in another rep?

Thanks!

About the ideas:

  • Add && exit at the end of the command, so you dont have to close de terminal manually after opening a file.
  • Add filtering to the command, like search only git files.

I'm thinking in a lot of features xD

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.