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

avoid showing the same note multiple times #22

Open
pvinis opened this issue Oct 16, 2018 · 12 comments
Open

avoid showing the same note multiple times #22

pvinis opened this issue Oct 16, 2018 · 12 comments

Comments

@pvinis
Copy link

pvinis commented Oct 16, 2018

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.

@alok
Copy link
Owner

alok commented Oct 16, 2018 via email

@pvinis
Copy link
Author

pvinis commented Oct 16, 2018

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 :)

@alok
Copy link
Owner

alok commented Oct 16, 2018 via email

@alok alok closed this as completed Oct 17, 2018
@harmenjanssen
Copy link

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...

@alok
Copy link
Owner

alok commented Jun 1, 2019

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.

@Nanodragon999
Copy link

Nanodragon999 commented Oct 21, 2019

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.

@dclift
Copy link

dclift commented Apr 5, 2020

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
Copy link

dclift commented Apr 6, 2020

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
Copy link

dclift commented Apr 19, 2020

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.

@zrwitter
Copy link

zrwitter commented Jun 4, 2020

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

@dclift
Copy link

dclift commented Jun 5, 2020

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.

@Andreilys
Copy link

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.

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

7 participants