ibhagwan / fzf-lua

Improved fzf.vim written in lua
GNU Affero General Public License v3.0
1.94k stars 133 forks source link

Direct lua callbacks in the mappings documentation #1310

Closed shmerl closed 1 day ago

shmerl commented 3 days ago

Have you RTFM'd?

Feature Request

I think this kind of example can be rewritten in more pure lua:

vim.keymap.set("n", "<c-P>", "<cmd>lua require('fzf-lua').files()<CR>", { silent = true })

as

vim.keymap.set("n", "<c-P>", function() require('fzf-lua').files() end, { silent = true })

Since vim.keymap.set supports Lua functions in rhs parameter.

ibhagwan commented 3 days ago

README was written before this was possible with neovim 0.5, can be simplified even more:


vim.keymap.set("n", "<c-P>", require('fzf-lua').files, { silent = true })
shmerl commented 3 days ago

A bit unrelated, but what's the point of silent=true? Supposedly it's for not echoing the mapping in the command line, but I don't get anything even without setting silent=true. Am I missing something or the default in neovim for vim.keymap.set is silent=true?

ibhagwan commented 3 days ago

A bit unrelated, but what's the point of silent=true? Supposedly it's for not echoing the mapping in the command line, but I don't get anything even without setting silent=true. Am I missing something or the default in neovim for vim.keymap.set is silent=true?

I’m not 100% sure but I think lua callback or <cmd> commands are already silent, it would probably make a difference if you mapped rhs to :lua ….

shmerl commented 3 days ago

Ah, yes. You are right - just tested a mapping with : instead of <Cmd> or callback and it's indeed echoing it unless silent is added. So it's not really needed in your example and it can be even further simplified :)

vim.keymap.set("n", "<c-P>", require('fzf-lua').files)