added neovim builtin providers

commands, command_history, search_history, keymaps, registers, spell_suggest
main
bhagwan 3 years ago
parent 48ce442b21
commit faad0474d4

@ -116,6 +116,7 @@ nnoremap <c-P> <cmd>lua require('fzf-lua').files()<CR>
## Commands
### Buffers & Files
| Command | List |
| --- | --- |
|`buffers`|open buffers|
@ -123,6 +124,10 @@ nnoremap <c-P> <cmd>lua require('fzf-lua').files()<CR>
|`oldfiles`|opened files history|
|`quickfix`|quickfix list|
|`loclist`|location list|
### Search
| Command | List |
| --- | --- |
|`grep`|search for a pattern with `grep` or `rg`|
|`grep_last`|run search again with the last pattern|
|`grep_cword`|search word under cursor|
@ -130,18 +135,18 @@ nnoremap <c-P> <cmd>lua require('fzf-lua').files()<CR>
|`grep_visual`|search visual selection|
|`grep_curbuf`|live grep current buffer|
|`live_grep`|live grep current project|
|`help_tags`|help tags|
|`man_pages`|man pages|
|`colorschemes`|color schemes|
|`builtin`|fzf-lua builtin methods|
### Git
| Command | List |
| --- | --- |
|`git_files`|`git ls-files`|
|`git_status`|`git status`|
|`git_commits`|git commit log (project)|
|`git_bcommits`|git commit log (buffer)|
|`git_branch`|git branches|
## LSP Commands
### LSP
| Command | List |
| --- | --- |
|`lsp_references`|References|
@ -155,6 +160,21 @@ nnoremap <c-P> <cmd>lua require('fzf-lua').files()<CR>
|`lsp_document_diagnostics`|Document Diagnostics|
|`lsp_workspace_diagnostics`|Workspace Diagnostics|
### Misc
| Command | List |
| --- | --- |
|`builtin`|fzf-lua builtin methods|
|`help_tags`|help tags|
|`man_pages`|man pages|
|`colorschemes`|color schemes|
|`commands`|neovim commands|
|`command_history`|command history|
|`search_history`|search history|
|`registers`|:registers|
|`keymaps`|key mappings|
|`spell_suggest`|spelling suggestions|
## Customization
I tried to make it as customizable as possible, if you find you need to change something that isnt below, open an issue and Ill do my best to add it.
@ -397,31 +417,24 @@ require('fzf-lua').setup{
EOF
```
### Known issues
- [ ] `live_grep` has icons disabled until I find a solution for fzf's
`change:reload` event
- [ ] Tested mostly with both `rg`, `fd` and `bat` installed, there might be
issues with the default `grep`, `find` and `head` alternatives
## TODO
- Add more providers
- [ ] Add more providers
+ [x] ~~LSP (refs, symbols, etc)~~ (2021-07-20)
+ [x] ~~git commits~~ (2021-08-05)
+ [x] ~~git branches~~ (2021-08-05)
+ [ ] vim commands
+ [ ] vim command history
+ [ ] vim keymaps
+ [ ] vim options
+ [ ] search history
+ [ ] tags
+ [x] nvim builtin:
* [x] ~~commands~~ (2021-08-14)
* [x] ~~command history~~ (2021-08-14)
* [x] ~~search history~~ (2021-08-14)
* [x] ~~registers~~ (2021-08-14)
* [x] ~~keymaps~~ (2021-08-14)
* [x] ~~spelling suggestions~~ (2021-08-14)
+ [ ] marks
+ [ ] registers
+ [ ] spelling suggestions
+ [ ] tags
- [ ] Built-in previewer with treesitter support
- [ ] Add built-in plugin documentation
- [ ] Add "hidden" options documentation
- [ ] Add FAQ
- [ ] Complete the Wiki
### Credits

@ -132,6 +132,30 @@ M.run_builtin = function(selected)
vim.cmd(string.format("lua require'fzf-lua'.%s()", method))
end
M.ex_run = function(selected)
if not selected then return end
local cmd = selected[1]
if #selected>1 then cmd = selected[2] end
vim.cmd("stopinsert")
vim.fn.feedkeys(string.format(":%s ", cmd))
end
M.search = function(selected)
if not selected then return end
local query = selected[1]
if #selected>1 then query = selected[2] end
vim.cmd("stopinsert")
utils.feed_keys_termcodes(string.format("/%s<CR>", query))
end
M.spell_apply = function(selected)
if not selected then return end
local word = selected[1]
if #selected>1 then word = selected[2] end
vim.cmd("normal! ciw" .. word)
vim.cmd("stopinsert")
end
M.help = function(selected)
local vimcmd = "help"
M.vimcmd(vimcmd, selected)

@ -308,13 +308,46 @@ M.globals.lsp = {
M.globals.builtin = {
prompt = 'Builtin> ',
winopts = {
win_height = 0.65,
win_width = 0.50,
win_height = 0.65,
win_width = 0.50,
},
actions = {
["default"] = actions.run_builtin,
},
}
M.globals.nvim = {
commands = {
prompt = 'Commands> ',
actions = {
["default"] = actions.ex_run,
},
},
command_history = {
prompt = 'Command History> ',
actions = {
["default"] = actions.ex_run,
},
},
search_history = {
prompt = 'Search History> ',
actions = {
["default"] = actions.search,
},
},
registers = {
prompt = 'Registers> ',
ignore_empty = true,
},
keymaps = {
prompt = 'Keymaps> ',
},
spell_suggest = {
prompt = 'Spelling Suggestions> ',
actions = {
["default"] = actions.spell_apply,
},
},
}
M.globals.file_icon_colors = {
["lua"] = "blue",
["vim"] = "green",

@ -68,6 +68,13 @@ M.help_tags = require'fzf-lua.providers.helptags'.helptags
M.man_pages = require'fzf-lua.providers.manpages'.manpages
M.colorschemes = require'fzf-lua.providers.colorschemes'.colorschemes
M.keymaps = require'fzf-lua.providers.nvim'.keymaps
M.registers = require'fzf-lua.providers.nvim'.registers
M.commands = require'fzf-lua.providers.nvim'.commands
M.command_history = require'fzf-lua.providers.nvim'.command_history
M.search_history = require'fzf-lua.providers.nvim'.search_history
M.spell_suggest = require'fzf-lua.providers.nvim'.spell_suggest
M.lsp_typedefs = require'fzf-lua.providers.lsp'.typedefs
M.lsp_references = require'fzf-lua.providers.lsp'.references
M.lsp_definitions = require'fzf-lua.providers.lsp'.definitions

@ -2,7 +2,6 @@ if not pcall(require, "fzf") then
return
end
local fzf = require "fzf"
local action = require("fzf.actions").action
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"

@ -2,9 +2,7 @@ if not pcall(require, "fzf") then
return
end
-- local fzf = require "fzf"
local fzf_helpers = require("fzf.helpers")
-- local path = require "fzf-lua.path"
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"

@ -2,7 +2,6 @@ if not pcall(require, "fzf") then
return
end
local fzf = require "fzf"
local fzf_helpers = require("fzf.helpers")
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"

@ -2,7 +2,6 @@ if not pcall(require, "fzf") then
return
end
-- local fzf = require "fzf"
local fzf_helpers = require("fzf.helpers")
local path = require "fzf-lua.path"
local core = require "fzf-lua.core"

@ -2,7 +2,6 @@ if not pcall(require, "fzf") then
return
end
local fzf = require "fzf"
local path = require "fzf-lua.path"
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"

@ -2,9 +2,6 @@ if not pcall(require, "fzf") then
return
end
local fzf = require "fzf"
-- local fzf_helpers = require("fzf.helpers")
-- local path = require "fzf-lua.path"
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"

@ -2,7 +2,6 @@ if not pcall(require, "fzf") then
return
end
local fzf = require "fzf"
local fzf_helpers = require("fzf.helpers")
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"

@ -2,7 +2,6 @@ if not pcall(require, "fzf") then
return
end
local fzf = require "fzf"
local action = require("fzf.actions").action
local core = require "fzf-lua.core"
local config = require "fzf-lua.config"

@ -0,0 +1,220 @@
if not pcall(require, "fzf") then
return
end
local action = require("fzf.actions").action
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"
local actions = require "fzf-lua.actions"
local M = {}
M.commands = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.commands)
coroutine.wrap(function ()
local commands = vim.api.nvim_get_commands {}
local prev_act = action(function (args)
local cmd = args[1]
if commands[cmd] then
cmd = vim.inspect(commands[cmd])
end
return cmd
end)
local entries = {}
for k, _ in pairs(commands) do
table.insert(entries, utils.ansi_codes.magenta(k))
end
table.sort(entries, function(a, b) return a<b end)
opts.nomulti = true
opts.preview = prev_act
local selected = core.fzf(opts, entries,
core.build_fzf_cli(opts),
config.winopts(opts))
if not selected then return end
actions.act(opts.actions, selected)
end)()
end
local history = function(opts, str)
coroutine.wrap(function ()
local history = vim.fn.execute("history " .. str)
history = vim.split(history, "\n")
local entries = {}
for i = #history, 3, -1 do
local item = history[i]
local _, finish = string.find(item, "%d+ +")
table.insert(entries, string.sub(item, finish + 1))
end
opts.nomulti = true
opts.preview = nil
opts.preview_window = 'hidden:down:0'
local selected = core.fzf(opts, entries,
core.build_fzf_cli(opts),
config.winopts(opts))
if not selected then return end
actions.act(opts.actions, selected)
end)()
end
M.command_history = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.command_history)
history(opts, "cmd")
end
M.search_history = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.search_history)
history(opts, "search")
end
M.registers = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.registers)
coroutine.wrap(function ()
local registers = { '"', "_", "#", "=", "_", "/", "*", "+", ":", ".", "%" }
-- named
for i = 0, 9 do
table.insert(registers, tostring(i))
end
-- alphabetical
for i = 65, 90 do
table.insert(registers, string.char(i))
end
local prev_act = action(function (args)
local r = args[1]:match("%[(.*)%] ")
local contents = vim.fn.getreg(r)
return contents or r
end)
local entries = {}
for _, r in ipairs(registers) do
local contents = vim.fn.getreg(r)
contents = contents:gsub("\n", utils.ansi_codes.magenta("\\n"))
if (contents and #contents > 0) or not opts.ignore_empty then
table.insert(entries, string.format("[%s] %s",
utils.ansi_codes.yellow(r), contents))
end
end
opts.nomulti = true
opts.preview = prev_act
local selected = core.fzf(opts, entries,
core.build_fzf_cli(opts),
config.winopts(opts))
if not selected then return end
actions.act(opts.actions, selected)
end)()
end
M.keymaps = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.keymaps)
coroutine.wrap(function ()
local modes = { "n", "i", "c" }
local keymaps = {}
local add_keymap = function(keymap)
-- hijack field
keymap.str = string.format("[%s:%s:%s]",
utils.ansi_codes.yellow(tostring(keymap.buffer)),
utils.ansi_codes.green(keymap.mode),
utils.ansi_codes.magenta(keymap.lhs))
local k = string.format("[%s:%s:%s]",
keymap.buffer, keymap.mode, keymap.lhs)
keymaps[k] = keymap
end
for _, mode in pairs(modes) do
local global = vim.api.nvim_get_keymap(mode)
for _, keymap in pairs(global) do
add_keymap(keymap)
end
local buf_local = vim.api.nvim_buf_get_keymap(0, mode)
for _, keymap in pairs(buf_local) do
add_keymap(keymap)
end
end
local prev_act = action(function (args)
local k = args[1]:match("(%[.*%]) ")
local v = keymaps[k]
if v then
-- clear hijacked field
v.str = nil
k = vim.inspect(v)
end
return k
end)
local entries = {}
for _, v in pairs(keymaps) do
table.insert(entries, string.format("%-50s %s",
v.str, v.rhs))
end
opts.nomulti = true
opts.preview = prev_act
local selected = core.fzf(opts, entries,
core.build_fzf_cli(opts),
config.winopts(opts))
if not selected then return end
actions.act(opts.actions, selected)
end)()
end
M.spell_suggest = function(opts)
-- if not vim.wo.spell then return false end
opts = config.normalize_opts(opts, config.globals.nvim.spell_suggest)
coroutine.wrap(function ()
local cursor_word = vim.fn.expand "<cword>"
local entries = vim.fn.spellsuggest(cursor_word)
if vim.tbl_isempty(entries) then return end
opts.nomulti = true
opts.preview = nil
opts.preview_window = 'hidden:down:0'
local selected = core.fzf(opts, entries,
core.build_fzf_cli(opts),
config.winopts(opts))
if not selected then return end
actions.act(opts.actions, selected)
end)()
end
return M

@ -2,9 +2,6 @@ if not pcall(require, "fzf") then
return
end
-- local fzf = require "fzf"
local fzf_helpers = require("fzf.helpers")
-- local path = require "fzf-lua.path"
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"

@ -3,8 +3,6 @@ if not pcall(require, "fzf") then
end
-- local fzf = require "fzf"
-- local fzf_helpers = require("fzf.helpers")
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"

@ -194,7 +194,7 @@ function M.send_ctrl_c()
vim.api.nvim_replace_termcodes("<C-c>", true, false, true), 'n', true)
end
function M.feed_key(key)
function M.feed_keys_termcodes(key)
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(key, true, false, true), 'n', true)
end

Loading…
Cancel
Save