Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim how to add key binding that accepts input

Tags:

c++

vim

I'm pretty new to vim but I'm trying to create some C++ IDE.

I'm used to ctrl f (or ctrl-shift-f) to help me find in files.. so I saw a plugin I liked called pss.

I'd like to replace ctrl-f with something that would accept input but still add parameters of it's own(*.cpp for example).. I was thinking of something like:

how can I do it correctly?

noremap <C-f>:Pss $1 *.cpp
like image 799
Alon Avatar asked Feb 03 '26 14:02

Alon


1 Answers

Since you have editing capabilities in the command-line, a commonly used approach just builds an incomplete mapping. You can position the cursor in the edit location, like this:

:noremap <C-f> :Pss  *.cpp<Left><Left><Left><Left><Left><Left>

After triggering the mapping (via <C-f>), you can insert the search pattern, and then trigger the search via <CR>.

Alternative

You can query for input via the input() function; its result can be inserted into the command-line via :execute:

:noremap <C-f> :execute 'Pss' input('Pattern: ') '*.cpp'<CR>
like image 184
Ingo Karkat Avatar answered Feb 05 '26 03:02

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!