Yggdroot / LeaderF

An efficient fuzzy finder that helps to locate files, buffers, mrus, gtags, etc. on the fly for both vim and neovim.
Apache License 2.0
2.15k stars 179 forks source link

how to set my own keymaps for my own extensions #977

Closed giceli closed 1 year ago

giceli commented 1 year ago

let g:Lf_HideHelp = 1 let g:Lf_WindowPosition = 'popup' let g:Lf_PreviewInPopup = 1 let g:Lf_StlSeparator = { \ 'left': "\ue0b0", \ 'right': "\ue0b2", \ 'font': "DejaVu Sans Mono for Powerline" \ }

" insert mode " c-v vertical " c-s split " c-x select let g:Lf_CommandMap = {'<c-]>' : [''], \ '' : [''], \ '' : [''], \ }

let g:Lf_UseCache = 0 let g:Lf_UseVersionControlTool = 0

let g:Lf_DefaultExternalTool = "rg"

let g:Lf_WildIgnore = { \ 'dir' : ['.svn', '.git', '.hg', '.vscode', '.clangd'], \ 'file': ['.so', ".o", ".py[co]", ".exe", "*.bak"] \ }

let g:Lf_Extensions = get(g:,'Lf_Extensions',{})

" for asynctasks function! s:lf_asynctask_sourcebase(atype = "") let rows = asynctasks#source(&columns * 48 / 100) let globalsource = [] let localsource = [] let scriptsource = [] let othersource = [] for row in rows let name = substitute(row[0],""," ","g") if split(name," ")[0] == a:atype || a:atype == "" if row[1][1:5] == "local" let localsource += [name . ' ' . row[1] . ' : ' . row[2]] elseif row[1][1:6] == "global" let globalsource += [name . ' ' . row[1] . ' : --' . row[2][20:]] elseif row[1][1:6] == "script" let scriptsource += [name . ' ' . row[1] . ' : ' . row[2]] else let othersource += [name . ' ' . row[1] . ' : ' . row[2]] endif endif endfor return localsource + globalsource + scriptsource + othersource endfunction

function! s:lf_asynctask_source_all(...) return s:lf_asynctask_source_base() endfunction function! s:lf_asynctask_source_run(...) return s:lf_asynctask_source_base("run") endfunction function! s:lf_asynctask_source_build(...) return s:lf_asynctask_source_base("build") endfunction

function! s:lf_asynctaskaccept(line, arg) let pos = stridx(a:line, '<') if pos < 0 return endif let name = strpart(a:line, 0, pos) let name = substitute(name, '^\s(.{-})\s$', '\1', '') let name = substitute(name, ' ', '', 'g') if name != '' exec "AsyncTask " . name endif endfunction function! s:lf_task_digest(line, mode) let pos = stridx(a:line, '<') if pos < 0 return [a:line, 0] endif let name = strpart(a:line, 0, pos-1) return [name,0] endfunction

function LfAddAsyncTask(name,sourceFunction,acceptFunction,digestFunction) let g:Lf_Extensions[a:name] = { \ 'source': string(function(a:sourceFunction))[10:-3], \ 'accept': string(function(a:acceptFunction))[10:-3], \ 'get_digest': string(function(a:digestFunction))[10:-3], \ 'highlights_def': { \ 'Lf_hl_funcScope': '^\zs.\ze<', \ 'Lf_hl_funcDirname': '^.\zs<.>\ze.', \ }, \ 'help' : 'navigate available tasks from asynctasks.vim', \ } endfunction

call LfAddAsyncTask("asynctaskAll","s:lf_asynctask_source_all","s:lf_asynctask_accept","s:lf_task_digest") call LfAddAsyncTask("asynctaskRun","s:lf_asynctask_source_run","s:lf_asynctask_accept","s:lf_task_digest") call LfAddAsyncTask("asynctaskBuild","s:lf_asynctask_source_build","s:lf_asynctask_accept","s:lf_task_digest")



### Describe your question, feature request, or bug.
How can set my own keymaps, when i add a new  Extensions.

### Steps to reproduce

### Actual behaviour

### Expected behaviour
when i add my own extensions, I can only use the default keymaps, and add my own keymaps for <CR>, but I do not know how to set my own keymaps with nmap/imap for this extensions
Yggdroot commented 1 year ago

Sorry, I don't understand what you are intended to do. What maps?

giceli commented 1 year ago

for example, if i use a variables ' Lf_Projects' to records all the project i have edited, I can use Leaderf to see the project i have edited before, i want to map '' to open the project, map 'd' to remove the project if i use variables 'Lf_Session' to records all the sessions i have saved. I can show all the sessions with Leaderf, I want to map '' to open the session, map 'd' to remove the session, map 's' to restore current session also, when i use vimspector, i can search the configs for my debug and show them with Leaderf, I want to map '' to start to debug, map 'd' to remove the debug config, use 'i' or 'e' to edit this debug config.

Yggdroot commented 1 year ago

https://github.com/Yggdroot/LeaderF/blob/43433aa8dad1601acf923d3c25fa3325799508aa/doc/leaderf.txt#L447-L472

giceli commented 1 year ago

thanks, it works, but i find that, it only works when g:Lf_WindowPosition != 'popup'

Yggdroot commented 1 year ago

Yes, only works for non-popup mode.

Yggdroot commented 1 year ago

Now g:Lf_NormalCommandMap is available. https://github.com/Yggdroot/LeaderF/blob/3ded37f92807d8c6ad831d5af2c4ff22bfd32fc8/doc/leaderf.txt#L523-L553