notational-fzf-vim icon indicating copy to clipboard operation
notational-fzf-vim copied to clipboard

avoid showing the same note multiple times

Open pvinis opened this issue 5 years ago • 12 comments

when what i typed matches the name of a note, that note appears multiple times as a result. it would make sense to only appear once. screenshot 2018-10-16 at 10 24 37 is there a way to configure that that im missing? thank you.

pvinis avatar Oct 16 '18 08:10 pvinis

Not easily. The way that this plugin works is by printing every line from all files and then filtering them by your query, hence the duplication. I personally like the feature since I use it to immediately jump to the correct line.

You can pass a query to it directly like :NV query and that won't be unique but it'll reduce the number of lines to filter from the outset.

alok avatar Oct 16 '18 08:10 alok

i do like the direct jumping to the correct line! that is awesome. but when i search for a note name, i would like it to be unique.

ill keep trying it out and see if i can figure out something. thank you :)

pvinis avatar Oct 16 '18 09:10 pvinis

This isn't meant for searching notes just by name. That's another command, and that's :Files from the fzf plugin. It can take a specific directory as an argument.

alok avatar Oct 16 '18 09:10 alok

I agree it shouldn't search just by name, it should definitely also search contents. Right now, though, long notes totally take over the search results list.

In the OP's example any other files matching "broad" will never show up (or at least be "below the fold"). I would also really like it if it shows a line per match, but now I'm getting every line, regardless of match, in case the title matches...

harmenjanssen avatar Dec 25 '18 08:12 harmenjanssen

I've been thinking about this, and I don't see a clean way to do it with fzf. However, skim has an interactive mode that seems promising, and I've been writing up an experimental version of this plugin that uses it.

alok avatar Jun 01 '19 21:06 alok

You could probably use folding (similar to what nou.vim and other folding plugin does). so it only fold the most duplicated query into either the most redundant or the filename. Although, not sure how it would be possible with fzf, unless you redraw the tui in vim or something.

Nanodragon999 avatar Oct 21 '19 07:10 Nanodragon999

Very glad this is still being considered. Skim seems like the right direction. If I run the NV as is for a simple query, the list is too large to be manageable:

2020-04-05_15-11

But if I use skim in interactive mode, and tell ripgrep to only print the paths with at least one match via the -l flag:

sk --ansi -i -c 'rg -i -l --color=always --line-number "{}"' --preview "$HOME/.vim/plugged/fzf.vim/bin/preview.sh {}" --preview-window down:70%

I'm able to actually scan the list easily and use the preview window to quickly scan my entries.

2020-04-05_15-12

This seems to be more in line with the original functionality of Notational Velocity.

That said, one of the ironic things is about this method is that it doesn't seem to search the actual filename, so you can miss entries if you search a term that is in the filename but not within the note itself. I couldn't find a way around this other than including the filename within the note itself. In the context of the plugin you just automate the inclusion of the filename during note creation. Something like :1put! =expand('%:t:r') to grab the filename and add it as the first line? If someone knows a method to search both the contents and the filename, that would be ideal.

So I'm not sure how to integrate this into the plugin. I've been playing around with it just passing the sk command to vim "$()" - but would obviously like to integrate it into the plugin. @alok is this close to the method you are using for your experimental version?

dclift avatar Apr 05 '20 21:04 dclift

Ok, here's a solution that searches both the filename and the file contents, and avoids showing the same note multiple times:

sk --ansi -i -c '{ rg --files | rg -S "{}" & rg -S -l --color=always --line-number "{}" }' --preview "$HOME/.vim/plugged/fzf.vim/bin/preview.sh {}" --preview-window down

Skim seems to be a drop in replacement for fzf, so I changed the command! -nargs=* -bang NV call fzf#run(fzf#wrap({... section to command! -nargs=* -bang NV call skim#run(skim#wrap({... which works, but when you add the -l files with matches flag the plugin fails to return results.

dclift avatar Apr 06 '20 19:04 dclift

Here is my final solution for a notational velocity clone in a single command, just run it in the directory with your notes.

sk --ansi -i -c "(rg --files | rg -S \"{}\" & rg -S -l \"{}\" & echo {}.txt) | sort | uniq" --bind 'ctrl-x:execute(vim {})+abort,enter:execute(vim {})+abort' --preview "preview.sh {}" --preview-window down:wrap

It searches filenames and the file contents, avoids showing the same note multiple times, shows previews using the fzf preview script, opens notes in vim and ctrl+x creates and opens a new note in vim with the search query.

dclift avatar Apr 19 '20 14:04 dclift

Here is my final solution for a notational velocity clone in a single command, just run it in the directory with your notes.

sk --ansi -i -c "(rg --files | rg -S \"{}\" & rg -S -l \"{}\" & echo {}.txt) | sort | uniq" --bind 'ctrl-x:execute(vim {})+abort,enter:execute(vim {})+abort' --preview "preview.sh {}" --preview-window down:wrap

It searches filenames and the file contents, avoids showing the same note multiple times, shows previews using the fzf preview script, opens notes in vim and ctrl+x creates and opens a new note in vim with the search query.

This is beautiful. I made a slight change to:

  1. provide full path of preview.sh
  2. have vim jump to the line containing the search query (technically the "command query" per skim documentation)

sk --ansi -i -c "(rg --files | rg -S \"{}\" & rg -S -l \"{}\" & echo {}.txt) | sort | uniq" --bind 'ctrl-x:execute(vim {}),enter:execute(sterm={cq} && vim -c "/$sterm" {})+abort' --preview "$HOME/.vim/plugged/fzf.vim/bin/preview.sh {}" --preview-window down:wrap

zrwitter avatar Jun 04 '20 21:06 zrwitter

Great idea @zrwitter re jumping to the line containing the search query!

I've been using this NV clone for the past month and a half and it's been painless.

The one feature I still want to integrate is a way to score the results by the date the files were edited. I saw the --tiebreak function in skim but there didn't seem to be a criteria for it there.

Ideally, all things being equal, I'd like the first search results to be the most recently edited file since usually you're working on a project and using the same files again and again. This was how notational velocity worked I believe.

I contacted the author of skim to inquire if he had any ideas but never heard back. If anyone has a spark of inspiration on an approach, would love to see possible solutions.

dclift avatar Jun 05 '20 00:06 dclift

Here is my final solution for a notational velocity clone in a single command, just run it in the directory with your notes. sk --ansi -i -c "(rg --files | rg -S \"{}\" & rg -S -l \"{}\" & echo {}.txt) | sort | uniq" --bind 'ctrl-x:execute(vim {})+abort,enter:execute(vim {})+abort' --preview "preview.sh {}" --preview-window down:wrap It searches filenames and the file contents, avoids showing the same note multiple times, shows previews using the fzf preview script, opens notes in vim and ctrl+x creates and opens a new note in vim with the search query.

This is beautiful. I made a slight change to:

  1. provide full path of preview.sh
  2. have vim jump to the line containing the search query (technically the "command query" per skim documentation)

sk --ansi -i -c "(rg --files | rg -S \"{}\" & rg -S -l \"{}\" & echo {}.txt) | sort | uniq" --bind 'ctrl-x:execute(vim {}),enter:execute(sterm={cq} && vim -c "/$sterm" {})+abort' --preview "$HOME/.vim/plugged/fzf.vim/bin/preview.sh {}" --preview-window down:wrap

This is great thanks @zrwitter @dclift.

Out of curiosity, is there a way to replicate the "highlighting" of the search term in the preview window? I.e. left side you can see where "Fruitional View" is highlighted in the file that contains the term.

Screen Shot 2021-01-02 at 5 46 47 PM

Also, it seems like the jump to the line containing search query functionality is case sensitive. So while it'll find the file with fruitional view, when you enter the file it'll display an error "E486: Pattern not found: fruitional view" before opening the file and starting at the top, since in the text the term is actually Fruitional View.

Andreilys avatar Jan 03 '21 01:01 Andreilys