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

WIP: Suggested improvements #49

Open
wants to merge 27 commits into
base: vim9
Choose a base branch
from

Conversation

mmrwoods
Copy link
Contributor

@mmrwoods mmrwoods commented Nov 18, 2024

  • Remove --column from ag and rg opts, unnecessary
  • Use smart case or ignore case with grep commands
  • Increase ASYNC_STEP to 10000, better performance
  • Add syntax highlighting for filetypes known to vim
  • Add support for fdfind (fd binary on Debian/Ubuntu)
  • Make FuzzyFiles respect .gitignore by default
  • Rename g:files_respect_gitignore to g:fuzzyy_files_respect_gitignore
  • Use git-grep as fallback for FuzzyGrep when no ag or rg found
  • Ignore binaries when using grep, git-grep, findstr
  • Rename fuzzyy_files_ignore_{file,dir} to fuzzyy_files_exclude_{file,dir}
  • Change default match hl from CurSearch to Special
  • Fix cursor restore in MacVim (don't change &guicursor, change hi-Cursor instead)
  • Fix FuzzyCommands for commands with arguments
  • Support rg for finding files when no fd installed
  • Rename enable_fuzzyy_keymaps to fuzzyy_enable_mapping
  • Remove default value for g:fuzzyy_buffers_exclude, unnecessary
  • Add custom fuzzyy highlight groups with defaults
  • Fudge smart-case for grep, git-grep, findstr
  • Fix fallback to git-grep, git-ls-files after chdir

TODO:

  • add g:fuzzyy_grep_exclude_{file,dir} (similar to 5e7a4cd)
  • support more custom highlighting options, results cursorline, individual popup borders etc.
  • prefer rg to ag and fd for FuzzyGrep and FuzzyFiles (faster than ag, one less external dependency)
  • allow files and grep commands or options to be overridden somehow
  • don't enable leader mappings by default, or at least add fewer mappings, this is seriously opinionated territory
  • replace g:fuzzyy_mru_project_only with :FuzzyyMruCwd command (referring to this as project only is a bit misleading anyway, current working directory is not necessarily project root, but :FuzzyyMruProject would be nice too)
  • rename :FuzzyyMRUFiles to FuzzyyMru because shorter, Files is obvious (I think), and :FuzzyyMRUCWD would be horrid

@mmrwoods mmrwoods force-pushed the suggested-improvements branch 15 times, most recently from 97461f4 to d691460 Compare November 24, 2024 10:45
@mmrwoods
Copy link
Contributor Author

Hi @Donaldttt,

First, thank you for Fuzzyy, it's a great plugin, I love the aim to have something that just works out of the box, that's exactly what I was looking for after using fzf.vim for years and leaderf for a while recently.

I think it's time I asked for your feedback on some of these suggested changes before going much further. They are mostly either minor bug fixes or changes aiming to improve the out of the box experience so it "just works" as expected for new users (as expected being obviously highly subjective). They are driven by my personal use over a couple of weeks and my thoughts on how this should work as a plugin I would recommend to relative newcomers to Vim (I have recommended it btw!).

If you have a little time could you take a look at let me know what you think. I don't expect you to agree with every change, but I hope I have explained each one adequately and you can understand why I've made it, if not, please let me know and I'll clarify.

Thanks!

Unnecessary as --vimgrep option ensures column numbers are included
@mmrwoods mmrwoods force-pushed the suggested-improvements branch 12 times, most recently from 5649c9c to 2c30337 Compare November 29, 2024 08:32
Yes, a breaking and contentious change, but also one I think most users
would find the least surprising default (LeaderF and Telescope.nvim both
support fd by default but also respect .gitignore by default). This will
disrupt existing users, but I still believe it's a worthwhile change.
Using --full-name outputs paths relative to the repository root, but
the other find commands output paths relative to the current directory.

Before this change, when git-ls-files was used in a repo subdirectory,
opening files from the results would not work as paths would not exist.
This behaves the same, but is, I think, easier to read and understand
Use fixed strings rather than regular expressions when searching with
grep program, consistent with options used for ag, rg, and findstr
fuzzyy options should really be prefixed with fuzzyy_
When in a git repo use git-grep when no ag or rg, include untracked
but respect gitignore. Similar to use of git-ls-files with FuzzyFiles.
For findstr, best we can do is ignore files with unprintable characters.

Note that I've replaced /i with /P for findstr, I didn't realise findstr
parameters were case-insensitive so I previously added /i, not realising
that /I was the same thing, and the search was already case-insensitive.
These options are used when gitignore is not, or cannot, be respected,
and in the case of the preferred files command, fd, sets -E/--exclude
options, which "overrides any other ignore logic" (see man fd)

The naming of these variables, using ignore rather than exclude, may be
confusing in this context, and possibly even more confusing if future
variables closely align with fd and rg options like --no-ignore and
--no-ignore-parent (as per telescope.nvim, e.g. no_ignore_parent)
CurSearch typically has solid background, which leads to a very hard to
read wall of solid color, often orange or yellow, when fuzzy matching.

I think this default should be replaced with something easier to read.
Telescope.nvim uses Special by default, so use Special. Personally I
prefer QuickFixLine as it's more consistent among color schemes, but
it's probably better to copy a convention from a very popular plugin.
Trying to restore cursor by saving and resetting &guicursor doesn't work
in MacVim r180 (Vim 9.1.727), when &guicursor starts at n:blinkon0 and
is restored after closing the popups, the cursor is no longer visible.

Fix by clearing the Cursor highlight group and restoring it instead.
This is similar to what LeaderF does (adds and then deletes a match).

Note that capturing the before state now happens when creating the popup
windows, not when loading popup.vim, to allow for color scheme changes.

P.S. Also tested that this works with hi-link, and with gVim on Windows.
Only execute the command if it has no arguments. If the command has
arguments, even optional arguments, place the command in the command
line on selection, followed by a single space (same as telescope.nvim)

Note: also tested with gVim on Windows
Avoid error executing another Fuzzy command from FuzzyCommands results

Error detected while processing function <SNR>148_MenuFilter:
line    1:
E716: Key not present in Dictionary: "1004"
Error detected while processing function <SNR>148_GeneralPopupCallback:
line   23:
E716: Key not present in Dictionary: "1004"

Note: unrelated to my other changes, the bug is present on vim9 branch
Enable err_cb for async jobs to run ag, rg, rd etc., if things go wrong,
users should be able to see that something has gone wrong (will be more
important when greater customisation of commands or options is allowed).
Do not include patterns specific to particular operating systems, build
tools, programming language etc., it's almost impossible to set defaults
including these that are widely applicable and stand the test of time.

The new defaults only include files known to Vim, i.e. swap files and
the default tags file, and the most common version control directories.

It should now be reasonable to always apply these exclusions, as I think
the original author of the feature did, but will add a separate commit.
This makes sense to me, the defaults are now set to values that you
probably always want to ignore, vim swap files, tags files, common
version control directories, and users may want to always exclude some
files or directories without adding to gitignore or other ignore files.

For example, I might like to add tags.* to this, for Vim gutentags.
Sure, I could add to a "global" ignore file, but that won't necessarily
work with --no-ignore-parent, and maybe I want --no-ignore-parent. Also,
fd and rg don't follow include directives in git config, so if you set a
"global" gitignore using core.excludesFile from a config file included
from your global gitconfig it doesn't work as expected with fd and rg.
- fuzzyy options should really be prefixed with fuzzyy_
- use "mappings" to avoid confusion with fuzzy_keymaps
No longer necessary, __vista__ buffers are unlisted anyway, and
FuzzyBuffers hides unlisted buffers. Also intentionally removed the
setting of a default value in plugin/fuzzyy.vim to be consistent with
how other options specific to particular autoload files are set.
Use :highlight command to create custom highlight groups for fuzzyy
highlighting, all linking to existing highlight groups by default.

There are no changes to the actual highlighting here, this just changes
how the matched highlight can be customised by the user, and allows
other highlight groups to be customised, rather than being hard-coded.
@Donaldttt
Copy link
Owner

Hi, thank you for all the work you have done. I have been very busy lately. I will take a look of these change soon.

@mmrwoods mmrwoods force-pushed the suggested-improvements branch 4 times, most recently from c4af10a to a1c6c34 Compare December 2, 2024 07:32
Automatically include ignore case option when there are no upper case
characters in pattern to search. Mimics ag and rg --smart-case option.
As the command strings for files and grep are computed at load time, the
command string is effectively cached, never computed again at runtime.

If the FuzzyyFiles or FuzzyyGrep commands are used first within a git
repo and the derived command is a git command, git-grep or git-ls-files,
that command will be used again after the user the changes the working
directory to somewhere that is not within a git repo, and won't work.

The same issue applies in reverse, user starts off in a non-git repo
directory, then changes to git repo, fallback git commands not used.

The fix for FuzzyyFiles is nice and neat, but fix for FuzzyyGrep is a
lot messier as a number of things change when the command changes. I'm
sure this can be improved, but better to fix first and improve later.
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

Successfully merging this pull request may close these issues.

2 participants