我想知道是否可以在 Vim 中创建一个映射(对于普通模式),允许用户在映射执行之前输入。
我想为我最常用的 grep 命令创建一个快捷方式的映射。我希望命令允许输入我正在搜索的内容,然后在输入时执行。
这就是我想要的:
nmap F :grep! "*user input*"<CR>:cw<CR>
我不知道如何暂停和接受用户输入。我什至以正确的方式思考这个问题吗?有没有更好的方法来做我想做的事?
最佳答案
有一个功能input(prompt [, text [, completion]])
:
The result is a String, which is whatever the user typed on the command-line. The {prompt} argument is either a prompt string, or a blank string (for no prompt). A '\n' can be used in the prompt to start a new line.
(来自
:help input()
)。对于诸如
:grep!
之类的事情,您可能必须使用字符串表达式构建命令,然后使用 :execute
它。
关于用户输入的 Vim 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14388703/