0

I'm using CtrlP plugin to switch to other files in Vim by pressing Ctrl-p. But this only works in normal mode. I want to trigger it by pressing the same set of keys in insert mode as well. How can I do that? I couldn't find any mapping for insert mode in the help doc.

  • 1
    Can't you remap it yourself with inoremap <C-p> <Esc>:CtrlP<CR>? – statox Oct 11 at 8:16
  • Thank you. It worked. – Kartik Chauhan Oct 11 at 9:01
1

You can do the mapping by yourself: Ctrlp provides an ex command to trigger the fuzzy finding: :CtrlP so you can create an insert mode mapping which will switch to command mode and trigger the command:

inoremap <C-p> <Esc>:CtrlP<CR>`

Note that as <C-p> is used to navigate the pop up menu, this mapping could create a unwanted behavior (I'm not sure I didn't test it) but in this case you should be able to use pumvisible() in an expression mapping to check if the menu is visible and trigger the built-in <C-p> or the CtrlP ex command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.