diff --git a/.SpaceVim.d/tasks.toml b/.SpaceVim.d/tasks.toml index e1cc66280..66a21cf64 100644 --- a/.SpaceVim.d/tasks.toml +++ b/.SpaceVim.d/tasks.toml @@ -321,3 +321,10 @@ [bundle-vim-zettelkasten-nvim.options.env] VIM = 'D:\Scoop\apps\neovim\current\share\nvim' 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' diff --git a/bundle/nvim-plug/README.md b/bundle/nvim-plug/README.md index 25d002300..9fdd319c3 100644 --- a/bundle/nvim-plug/README.md +++ b/bundle/nvim-plug/README.md @@ -44,14 +44,15 @@ require('plug').add({ ## Plugin Spec -| name | description | -| --------- | --------------------------------------------------------------------------------------------------- | -| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` | -| `cmds` | `table`, commands lazy loading | -| `events` | `table`, events lazy loading | -| `on_ft` | `table`, filetypes lazy loading | -| `type` | `string`, plugin type including `color`, `plugin` | -| `build` | `string` or `table`, executed by [job](https://spacevim.org/api/job/) api | +| name | description | +| --------- | --------------------------------------------------------------------------------------- | +| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` | +| `cmds` | `table`, commands lazy loading | +| `events` | `table`, events lazy loading | +| `on_ft` | `table`, filetypes lazy loading | +| `on_map` | `table`, key bindings lazy loading | +| `type` | `string`, plugin type including `color`, `plugin` | +| `build` | `string` or `table`, executed by [job](https://spacevim.org/api/job/) api | | `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped | ## Commands diff --git a/bundle/nvim-plug/lua/plug/hooks.lua b/bundle/nvim-plug/lua/plug/hooks.lua index a96893ef1..44d9390b3 100644 --- a/bundle/nvim-plug/lua/plug/hooks.lua +++ b/bundle/nvim-plug/lua/plug/hooks.lua @@ -53,4 +53,39 @@ function M.on_ft(fts, plugSpec) }) 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 = '' + 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 diff --git a/bundle/nvim-plug/lua/plug/init.lua b/bundle/nvim-plug/lua/plug/init.lua index 0816ed6d8..daaf1d169 100644 --- a/bundle/nvim-plug/lua/plug/init.lua +++ b/bundle/nvim-plug/lua/plug/init.lua @@ -36,7 +36,11 @@ function M.add(plugins) hooks.on_ft(plug.on_ft, plug) 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) end ::continue:: diff --git a/bundle/nvim-plug/lua/plug/loader.lua b/bundle/nvim-plug/lua/plug/loader.lua index d090c1ae6..5c9a3f613 100644 --- a/bundle/nvim-plug/lua/plug/loader.lua +++ b/bundle/nvim-plug/lua/plug/loader.lua @@ -31,7 +31,7 @@ local function is_local_plugin(plugSpec) end local function unique_name(plugSpec) - local s = vim.split(plugSpec, '/') + local s = vim.split(plugSpec[1], '/') return s[#s] end @@ -90,7 +90,7 @@ function M.load(plugSpec) if vim.fn.isdirectory(plugSpec.rtp) == 1 then vim.opt.runtimepath:append(plugSpec.rtp) 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 vim.cmd.source(f) end diff --git a/bundle/nvim-plug/test/init.lua b/bundle/nvim-plug/test/init.lua index d143c4a88..b84e80809 100644 --- a/bundle/nvim-plug/test/init.lua +++ b/bundle/nvim-plug/test/init.lua @@ -11,21 +11,24 @@ vim.opt.runtimepath:append('~/.SpaceVim') require('plug').setup({ bundle_dir = 'D:/bundle_dir', - }) -require("plug").add({ - { - "wsdjeg/scrollbar.vim", - events = { "VimEnter" }, - config = function() - end - }, - { - "wsdjeg/flygrep.nvim", - cmds = { "FlyGrep" }, +require('plug').add({ + { + 'wsdjeg/scrollbar.vim', + events = { 'VimEnter' }, + config = function() end, + }, + { + 'wsdjeg/flygrep.nvim', + cmds = { 'FlyGrep' }, config = function() require('flygrep').setup() - end - }, + end, + }, + { + 'rhysd/clever-f.vim', + on_map = { '(clever-f' }, + }, }) +vim.cmd('nmap f (clever-f-f)')