用户输入的 Vim 映射 [英] Vim mapping with user input
问题描述
我想知道是否可以在 Vim 中创建一个映射(对于普通模式),允许用户在映射执行之前输入.
I'm wondering if it's possible in Vim to create a mapping (for normal mode) that allows user input before the mapping executes.
我想为我最常用的 grep 命令创建一个快捷方式的映射.我希望命令允许输入我正在搜索的内容,然后在输入时执行.
I want to create a mapping for a shortcut for my most used grep command. I want the command to allow to to enter what I'm searching for then execute on enter.
这正是我想要的:
nmap F :grep! "*user input*"<CR>:cw<CR>
我不知道如何暂停和接受用户输入.我什至以正确的方式思考这个问题吗?有没有更好的方法来做我想做的事?
I can't figure out how to pause and take user input. Am I even thinking about this the right way? Are there better ways to do what I'm trying to?
推荐答案
另一种方法是创建自定义命令并使用映射来调用新命令.
An alternative would be create a custom command and use a mapping to call the new command.
command! -nargs=+ -complete=file -bar Grep grep! <args>|cw
现在您可以创建映射:
nnoremap <f2> :Grep<space>
您可能还想避免映射 F
键,因为它是一个非常方便的映射.
You probably also want to stay away from mapping the F
key as it a pretty handy mapping.
有关更多帮助,请参阅:
For more help see:
:h :command
这篇关于用户输入的 Vim 映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!