简体   繁体   中英

How to customize the mappings inside CtrlP's prompt - VIM

I'm using ctrlP plugin.

According to the ctrlp's doc I should be able to remap like this

  let g:ctrlp_prompt_mappings = { 'PrtSelectMove("k")': ['<c-u>', '<up>'] }
  let g:ctrlp_prompt_mappings = { 'PrtSelectMove("j")': ['<c-d>', '<down>'] }
  let g:ctrlp_prompt_mappings = { 'PrtDelete()'       : ['<c-k>', '<del>'] }
  let g:ctrlp_prompt_mappings = { 'PrtExit()'         : ['<c-l>', '<esc>'] }

But it doesn't work, I tried a few variations - still getting the same result.

I want to remap this four lines ( from doc ):

\ 'PrtDelete()':          ['<del>'],
\ 'PrtSelectMove("j")':   ['<c-j>', '<down>'],
\ 'PrtSelectMove("k")':   ['<c-k>', '<up>'],
\ 'PrtExit()':            ['<esc>', '<c-c>', '<c-g>'],

+++UPDATE+++

  let g:ctrlp_prompt_mappings = {
  \ 'PrtDelete()': ['<c-k>', '<del>'],
  \ 'PrtExit()': ['<esc>', '<c-l>', '<c-g>'],
  \ 'PrtSelectMove("k")': ['<c-u>', '<up>'],
  \ 'PrtSelectMove("j")': ['<c-d>', '<down>'],
  \}

Only <cu> does work. <ck>, <cl>, <cd> doesn't work.

when I do :echo g:ctrlp_prompt_mappings

{'PrtDelete()': ['<c-k>', '<del>'], 'PrtSelectMove("j")': ['<c-d>', '<down>'], 'PrtExit()': ['<esc>', '<c-l>', '<c-g>'], 'PrtSelectMove("k")': ['<c-u>', '<up>']}

+++UPDATE2+++

  let g:ctrlp_prompt_mappings = {
  \ 'PrtExit()':   ['<c-l>', '<esc>'],
  \ 'PrtSelectMove("k")': ['<c-u>', '<up>'],
  \ 'PrtSelectMove("j")': ['<c-d>', '<down>'],
  \ 'PrtBS()': ['<c-k>', '<bs>', '<c-]>'],
  \ 'ToggleByFname()': [''],
  \ 'PrtCurRight()': ['<right>'],
  \}

everything works. ( <cl>, <cd> ) started working because I remove them from

  \ 'ToggleByFname()':      [''],
  \ 'PrtCurRight()':        ['<right>'],

If you copy your suggested solution to the clipboard,

  let g:ctrlp_prompt_mappings = { 'PrtSelectMove("k")': ['<c-u>', '<up>'] }
  let g:ctrlp_prompt_mappings = { 'PrtSelectMove("j")': ['<c-d>', '<down>'] }
  let g:ctrlp_prompt_mappings = { 'PrtDelete()'       : ['<c-k>', '<del>'] }
  let g:ctrlp_prompt_mappings = { 'PrtExit()'         : ['<c-l>', '<esc>'] }

, and then "source" it using :@+ , you will notice that you are actually overwriting the variable three times, so only the last line remains:

:echo g:ctrlp_prompt_mappings

output: {'PrtExit()': ['<c-l>', '<esc>']}

It would be better if you follow the pattern described at the documentation:

 *'g:ctrlp_prompt_mappings'*
Use this to customize the mappings inside CtrlP's prompt to your liking. You
only need to keep the lines that you've changed the values (inside []): >
let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<bs>', '<c-]>'],
\ 'PrtDelete()': ['<del>'],
\ 'PrtDeleteWord()': ['<c-w>'],
\ 'PrtClear()': ['<c-u>'],
\ 'PrtSelectMove("j")': ['<c-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
...
\}

Each block of braces comprises a dictionary. Your approach defines four different dictionaries and assign all of them to the same variable, while the form described by the documentation defines a single one with multiple key/value pairs. Check :help dict for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM