Code Monkey home page Code Monkey logo

Comments (12)

alok avatar alok commented on August 16, 2024 8

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.

from notational-fzf-vim.

zrwitter avatar zrwitter commented on August 16, 2024 4

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

from notational-fzf-vim.

dclift avatar dclift commented on August 16, 2024 3

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.

from notational-fzf-vim.

harmenjanssen avatar harmenjanssen commented on August 16, 2024 1

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

from notational-fzf-vim.

dclift avatar dclift commented on August 16, 2024 1

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?

from notational-fzf-vim.

alok avatar alok commented on August 16, 2024

from notational-fzf-vim.

pvinis avatar pvinis commented on August 16, 2024

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

from notational-fzf-vim.

alok avatar alok commented on August 16, 2024

from notational-fzf-vim.

Nanodragon999 avatar Nanodragon999 commented on August 16, 2024

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.

from notational-fzf-vim.

dclift avatar dclift commented on August 16, 2024

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.

from notational-fzf-vim.

dclift avatar dclift commented on August 16, 2024

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.

from notational-fzf-vim.

Andreilys avatar Andreilys commented on August 16, 2024

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.

from notational-fzf-vim.

Related Issues (20)

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.