1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-14 03:37:59 +08:00

feat(nvim-plug): support on_map opt

This commit is contained in:
Eric Wong 2025-02-05 11:31:31 +08:00
parent 8368712a5e
commit c21cea3595
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
6 changed files with 74 additions and 24 deletions

View File

@ -321,3 +321,10 @@
[bundle-vim-zettelkasten-nvim.options.env] [bundle-vim-zettelkasten-nvim.options.env]
VIM = 'D:\Scoop\apps\neovim\current\share\nvim' VIM = 'D:\Scoop\apps\neovim\current\share\nvim'
VIMRUNTIME = 'D:\Scoop\apps\neovim\current\share\nvim\runtime' VIMRUNTIME = 'D:\Scoop\apps\neovim\current\share\nvim\runtime'
[bundle-nvim-plug]
command = 'wt.exe'
args = ['-d', 'C:\Users\wsdjeg\.SpaceVim\bundle\nvim-plug', 'D:\Scoop\apps\neovim\current\bin\nvim.exe', '-Nu', 'test/init.lua']
isBackground = true
[bundle-nvim-plug.options.env]
VIM = 'D:\Scoop\apps\neovim\current\share\nvim'
VIMRUNTIME = 'D:\Scoop\apps\neovim\current\share\nvim\runtime'

View File

@ -45,11 +45,12 @@ require('plug').add({
## Plugin Spec ## Plugin Spec
| name | description | | name | description |
| --------- | --------------------------------------------------------------------------------------------------- | | --------- | --------------------------------------------------------------------------------------- |
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` | | `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
| `cmds` | `table<string>`, commands lazy loading | | `cmds` | `table<string>`, commands lazy loading |
| `events` | `table<string>`, events lazy loading | | `events` | `table<string>`, events lazy loading |
| `on_ft` | `table<string>`, filetypes lazy loading | | `on_ft` | `table<string>`, filetypes lazy loading |
| `on_map` | `table<string>`, key bindings lazy loading |
| `type` | `string`, plugin type including `color`, `plugin` | | `type` | `string`, plugin type including `color`, `plugin` |
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api | | `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped | | `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped |

View File

@ -53,4 +53,39 @@ function M.on_ft(fts, plugSpec)
}) })
end end
function M.on_map(maps, plugSpec)
for _, lhs in ipairs(maps) do
vim.keymap.set('n', lhs, function()
for _, v in ipairs(plugSpec.on_map) do
vim.keymap.del('n', v, {})
end
plugin_loader.load(plugSpec)
local termstr = '<M-_>'
local input = ''
vim.fn.feedkeys(termstr, 'n')
while true do
local char = vim.fn.getchar()
if type(char) == 'number' then
input = input .. vim.fn.nr2char(char)
else
input = input .. char
end
local idx = vim.fn.stridx(input, termstr)
if idx >= 1 then
input = string.sub(input, 1, idx)
break
elseif idx == 0 then
input = ''
break
end
end
vim.fn.feedkeys(lhs .. input, 'm')
end, {})
end
end
return M return M

View File

@ -36,7 +36,11 @@ function M.add(plugins)
hooks.on_ft(plug.on_ft, plug) hooks.on_ft(plug.on_ft, plug)
end end
if not plug.events and not plug.cmds and not plug.on_ft then if plug.on_map then
hooks.on_map(plug.on_map, plug)
end
if not plug.events and not plug.cmds and not plug.on_ft and not plug.on_map then
loader.load(plug) loader.load(plug)
end end
::continue:: ::continue::

View File

@ -31,7 +31,7 @@ local function is_local_plugin(plugSpec)
end end
local function unique_name(plugSpec) local function unique_name(plugSpec)
local s = vim.split(plugSpec, '/') local s = vim.split(plugSpec[1], '/')
return s[#s] return s[#s]
end end
@ -90,7 +90,7 @@ function M.load(plugSpec)
if vim.fn.isdirectory(plugSpec.rtp) == 1 then if vim.fn.isdirectory(plugSpec.rtp) == 1 then
vim.opt.runtimepath:append(plugSpec.rtp) vim.opt.runtimepath:append(plugSpec.rtp)
if vim.fn.has('vim_starting') ~= 1 then if vim.fn.has('vim_starting') ~= 1 then
local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, 'plugin/*.{lua,vim}') local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, "plugin/*.{lua,vim}", 0, 1)
for _, f in ipairs(plugin_directory_files) do for _, f in ipairs(plugin_directory_files) do
vim.cmd.source(f) vim.cmd.source(f)
end end

View File

@ -11,21 +11,24 @@ vim.opt.runtimepath:append('~/.SpaceVim')
require('plug').setup({ require('plug').setup({
bundle_dir = 'D:/bundle_dir', bundle_dir = 'D:/bundle_dir',
}) })
require("plug").add({ require('plug').add({
{ {
"wsdjeg/scrollbar.vim", 'wsdjeg/scrollbar.vim',
events = { "VimEnter" }, events = { 'VimEnter' },
config = function() config = function() end,
end
}, },
{ {
"wsdjeg/flygrep.nvim", 'wsdjeg/flygrep.nvim',
cmds = { "FlyGrep" }, cmds = { 'FlyGrep' },
config = function() config = function()
require('flygrep').setup() require('flygrep').setup()
end end,
},
{
'rhysd/clever-f.vim',
on_map = { '<Plug>(clever-f' },
}, },
}) })
vim.cmd('nmap f <Plug>(clever-f-f)')