1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 10:20:05 +08:00

feat(mapping): add SPC f v s to view scriptnames

This commit is contained in:
wsdjeg 2022-05-18 13:36:05 +08:00
parent 076c0fe4a6
commit 3daea9e7ae
4 changed files with 170 additions and 108 deletions

View File

@ -297,6 +297,17 @@ function! s:defind_fuzzy_finder() abort
\ ]
\ ]
let lnum = expand('<slnum>') + s:unite_lnum - 4
call SpaceVim#mapping#space#def('nnoremap', ['f', 'v', 's'], 'Telescope scriptnames',
\ ['open-custom-configuration',
\ [
\ '[SPC f v d] is to open the custom configuration file for SpaceVim',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
\ , 1)
endfunction
" function() wrapper

View File

@ -1,5 +1,6 @@
lua require('telescope').load_extension('menu')
lua require('telescope').load_extension('messages')
lua require('telescope').load_extension('scriptnames')
lua <<EOF
local actions = require("telescope.actions")
require("telescope").setup{

View File

@ -1502,9 +1502,10 @@ The first item is the name of the tool, the second one is the default searching
Convenient key bindings are located under the prefix `SPC f v` to quickly navigate between Vim and SpaceVim specific files.
| Key Bindings | Descriptions |
| ------------ | --------------------------------------- |
| ------------ | ------------------------------------------------ |
| `SPC f v v` | display and copy SpaceVim version |
| `SPC f v d` | open SpaceVim custom configuration file |
| `SPC f v s` | list all loaded vim scripts, like `:scriptnames` |
### Available layers

View File

@ -0,0 +1,49 @@
local action_state = require("telescope.actions.state")
local actions = require("telescope.actions")
local conf = require("telescope.config").values
local entry_display = require("telescope.pickers.entry_display")
local finders = require("telescope.finders")
local pickers = require("telescope.pickers")
local sp_file = require('spacevim.api').import('file')
local function prepare_output_table()
local lines = {}
local scripts = vim.api.nvim_command_output("scriptnames")
for script in scripts:gmatch("[^\r\n]+") do
table.insert(lines, script)
end
return lines
end
local function show_script_names(opts)
opts = opts or {}
pickers.new(opts, {
prompt_title = "Script Names",
finder = finders.new_table {
results = prepare_output_table()
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local entry = action_state.get_selected_entry()
-- print(vim.inspect(selection))
-- vim.cmd("e " + entry.value)
vim.cmd('e ' .. vim.fn.split(entry.value, ": ")[2])
end)
return true
end,
}):find()
end
local function run()
show_script_names()
end
return require("telescope").register_extension({
exports = {
-- Default when to argument is given, i.e. :Telescope scriptnames
scriptnames = run,
},
})