camspiers / snap

A fast finder system for neovim.
The Unlicense
490 stars 17 forks source link

Snap doesn't support vim-plug #2

Closed qazip closed 3 years ago

qazip commented 3 years ago

I copied your example config (https://gist.github.com/camspiers/686395ab3bda4a0d00684d72acc24c23) to a snap.lua and then called it in my init. I get the following error:

E5113: Error while calling lua chunk: /home/myuser/blabla/snap.lua:1: loop or previous error loading module 'snap'

I installed snap with Plug 'camspiers/snap'.

camspiers commented 3 years ago

I suspect this means snap doesn't currently support being installed by vim plug. Genuine issue here, thanks!

astridlyre commented 3 years ago

I had no issues installing with Vim Plug. I did find that the key bindings did not seem to work as given in the examples. This configuration works for me (in vim config directory as lua/snap/init.lua):

local snap = require 'snap'

local fzf = snap.get 'consumer.fzf'
local limit = snap.get 'consumer.limit'
local producer_file = snap.get 'producer.ripgrep.file'
local producer_vimgrep = snap.get 'producer.ripgrep.vimgrep'
local producer_buffer = snap.get 'producer.vim.buffer'
local producer_oldfile = snap.get 'producer.vim.oldfile'
local select_file = snap.get 'select.file'
local select_vimgrep = snap.get 'select.vimgrep'
local preview_file = snap.get 'preview.file'
local preview_vimgrep = snap.get 'preview.vimgrep'

local s = {}

s.files = function()
    snap.run({
        prompt = 'Files',
        producer = fzf(producer_file),
        select = select_file.select,
        multiselect = select_file.multiselect,
        views = {preview_file}
    })
end

s.grep = function()
    snap.run({
        prompt = 'Grep',
        producer = limit(10000, producer_vimgrep),
        select = select_vimgrep.select,
        multiselect = select_vimgrep.multiselect,
        views = {preview_vimgrep}
    })
end

s.buffers = function()
    snap.run({
        prompt = 'Buffers',
        producer = fzf(producer_buffer),
        select = select_file.select,
        multiselect = select_file.multiselect,
        views = {preview_file}
    })
end

s.oldfiles = function()
    snap.run({
        prompt = 'Oldfiles',
        producer = fzf(producer_oldfile),
        select = select_file.select,
        multiselect = select_file.multiselect,
        views = {preview_file}
    })
end

return s

Then, I made bindings in my init.vim:

nnoremap <leader>ff <cmd>lua require'snap'.files()<cr>
nnoremap <leader>fg <cmd>lua require'snap'.grep()<cr>
nnoremap <leader>fb <cmd>lua require'snap'.buffers()<cr>
nnoremap <leader>fo <cmd>lua require'snap'.oldfiles()<cr>
fabiomcosta commented 3 years ago

I had the same issue with nvim-treesiter, it's not vim-plug or this plugin, but you have to structure your init file in a specific way.

Here is how it works for me with vim-plug using my ~/.config/nvim/init.vim file only:

call plug#begin(expand('~/.local/share/nvim/plugged'))
  Plug 'camspiers/snap'
call plug#end()

lua <<EOF
local snap = require'snap'
snap.register.map({'n'}, {'<LEADER>f'}, function ()
  snap.run {
    producer = snap.get'consumer.fzf'(snap.get'producer.ripgrep.file'),
    select = snap.get'select.file'.select,
    multiselect = snap.get'select.file'.multiselect,
    views = {snap.get'preview.file'}
  }
end)
EOF

Hello Cam :) Fantastic work!

fabiomcosta commented 3 years ago

I did not try to use it with fzy though, that seemed like it might not work... but maybe it does, i'd be curious to see that.

qazip commented 3 years ago

@astridlyre, I did just as you did and I still can't get it to work.

camspiers commented 3 years ago

I have tested and I was able to get snap installed with vim-plug, so this might be a different issue than general support. Hey @fabiomcosta, hope you are doing well!

KyleAMathews commented 3 years ago

I got it to work by swapping in fzf for fzy in https://gist.github.com/camspiers/686395ab3bda4a0d00684d72acc24c23

I'd installed fzy with homebrew but snap apparently requires the lua port which I didn't investigate how to install.

It's working super nicely!