vim - 如何自定义 CtrlP 提示符内的映射 - VIM

标签 vim ctrlp

我正在使用ctrlP插件。

根据ctrlp's doc我应该能够像这样重新映射

  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>'] }

但是它不起作用,我尝试了一些变体 - 仍然得到相同的结果。

我想重新映射这四行( from doc ):

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

+++更新+++

  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>'],
  \}

<c-u>确实有效。 <c-k>, <c-l>, <c-d>不起作用。

当我这样做时: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>']}

+++更新2+++

  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>'],
  \}

一切正常。 ( <c-l>, <c-d> ) 开始工作,因为我将它们从

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

最佳答案

如果您将建议的解决方案复制到剪贴板,

  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>'] }

,然后使用 :@+“获取”它,您会注意到实际上将变量覆盖了三次,因此只剩下最后一行:

:echo g:ctrlp_prompt_mappings

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

如果您遵循文档中描述的模式会更好:

 *'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>'],
...
\}

每个大括号 block 都包含一个字典。您的方法定义了四个不同的字典并将它们全部分配给同一个变量,而文档描述的形式定义了一个具有多个键/值对的字典。检查 :help dict 了解更多信息。

关于vim - 如何自定义 CtrlP 提示符内的映射 - VIM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32861750/

相关文章:

regex - 是否可以更改 vim regexp 方言?

vim - Ctrlp 在项目中查找

vim - ctrlp :CtrlPTag search slow

vim - gvim 的 CtrlP 找不到我的文件,max_files 参数已设置

python - vim python-mode 中的自动滚动输出

vim - 以相反顺序完成文件名

vim - 描述 vim 替换

vim - :vsplit autocomplete not working with/django/directory in VIM

ctrlp - 如何在新窗口中按 CtrlP 拆分打开多个文件

vim - 我无法退出 Vim,我点击了 escape 并尝试了 :q :x :qx