Comments (12)
Oh, deleting the sink*
and sinklist
keys from the table might work better:
local fzf_wrapped_options = vim.call("fzf#wrap", { source = source, options = { "--prompt", prompt }, dir = root })
fzf_wrapped_options['sink*'] = nil
fzf_wrapped_options.sinklist = nil
vim.call("fzf#run", fzf_wrapped_options)
from nvim-lua-guide.
Right, deleting sink*
and sinklist
removes the default action entirely so selecting an item does nothing. Passing sink = 'edit'
to fzf#wrap()
should to the trick since it prevents it from returning a table with vim.NIL
:
vim.cal('fzf#run', vim.call("fzf#wrap", { source = source, options = { "--prompt", prompt }, dir = root, sink = 'edit' }))
(sorry for the confusion, I'm learning about the internals of fzf.vim
as I debug this)
from nvim-lua-guide.
Some VimScript functions that modify a variable in-place behave differently in Lua, since the conversion creates a copy:
let s:list = [1, 2, 3]
let s:newlist = map(s:list, {_, v -> v * 2})
echo s:list
" [2, 4, 6]
echo s:newlist
" [2, 4, 6]
local tbl = {1, 2, 3}
local newtbl = vim.fn.map(tbl, function(_, v) return v * 2 end)
print(vim.inspect(tbl)) -- { 1, 2, 3 }
print(vim.inspect(newtbl)) -- { 2, 4, 6 }
This may also have performance implications?
from nvim-lua-guide.
Does this include set options like
vim.o.list = true
and in nvim cmdline:
:lua print(vim.o.list)
?
I cant print it, but the set option has an effect (applying listchars).
from nvim-lua-guide.
'list'
is a window-local option, so I don't think the error is related to type conversion, you'd have to use vim.wo.list
from nvim-lua-guide.
Thanks for mentioning this, I was rewriting my fzf
config into lua
and trying to figure out what was wrong was driving me crazy! It's only because of your mention of fzf#wrap
that I found this.
My code right now looks something like this:
local cmd = string.format(
":call fzf#run(fzf#wrap({'source': '%s', 'options': ['--prompt', '%s'], 'dir': '%s'}))",
source,
prompt,
root
)
vim.cmd(cmd)
Is it possible to re-write this into lua and avoid the string interpolation?
from nvim-lua-guide.
For Lua callbacks, there's this trick I learned by reading nvim-lspfuzzy's source code: https://github.com/ojroques/nvim-lspfuzzy/blob/f41f8b03a8eacee578b2b4f14866163538fcfe37/lua/lspfuzzy.lua#L138-L142
I'm surprised your example doesn't work though, it looks as though you're only passing strings to fzf#wrap()
from nvim-lua-guide.
I think that fzf#wrap
returns a function that's then passed to fzf#run
. At least that's my theory.
I re-wrote the function into this:
vim.call("fzf#run", vim.call("fzf#wrap", { source = source, options = { "--prompt", prompt }, dir = root }))
And after I pick a file from the prompt, I get an error:
Error detected while processing function 11[30]..<SNR>35_callback:
line 23:
Vim(call):E718: Funcref required
The output of fzf#wrap itself is a table/dict, and I suspect one of those vim.NIL
values are actually functions:
{
_action = {
["ctrl-t"] = "tab split",
["ctrl-v"] = "vsplit",
["ctrl-x"] = "split"
},
dir = "/home/hugo/.dotfiles",
down = "40%",
options = " '--prompt' 'git> ' --expect=ctrl-v,ctrl-x,ctrl-t",
["sink*"] = vim.NIL,
sinklist = vim.NIL,
source = "git ls-files --cached --modified --others --exclude-standard | uniq"
}
from nvim-lua-guide.
Oh, yeah, that link confirms it: sink
is a function.
from nvim-lua-guide.
fzf#wrap()
does indeed return default functions if no sink
option is passed: https://github.com/junegunn/fzf/blob/a91a67668e0830a8cf9a792c4949e03b4189f097/plugin/fzf.vim#L422-L429
Passing sink = 'edit'
to fzf#wrap()
might fix your problem
from nvim-lua-guide.
That worked, thanks!
from nvim-lua-guide.
Ugh, I cheered too soon. It doesn't work. It lets me pick a file but does nothing.
I though it worked because I'd picked the same file and it didn't error. :(
from nvim-lua-guide.
Related Issues (20)
- neovim autocommands got merged, describe them in guide HOT 4
- threading support for lua via libuv got merged, link to good tutorial on usage
- suggestions on how to reload keymaps and options
- How to get &ft from lua HOT 4
- Describe how to create user commands that support ranges
- explain that `vim.api.nvim_set_keymap(mode, ..)` is first char of `:lua print(vim.api.nvim_get_mode().mode)` and hint that there is a minor mode HOT 2
- FFI Library: calling native C function
- Remove problematic flags emoji
- Can we use this guide in Neovim? HOT 3
- Add a Table of content HOT 1
- add protected call for make sure the first run will work properlly
- add recommended formatter setup for lua and nvim lua plugin template
- Question: lua replacement for `executable()`? HOT 2
- how to read the command arguments `:command arg1 arg2` with lua HOT 2
- vim.api.nvim_exec() example gives error HOT 1
- lua user commands pr landed, so describe them in guide HOT 1
- Improper handling of relative paths with spaces HOT 2
- How to let `vim.cmd` accept the range from visual selection HOT 1
- Create keymap to open new file adjacent to current file HOT 6
- DEPRECATED replaced by mode option HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvim-lua-guide.