我可以创建一个映射来搜索光标下的单词,如下所示:
noremap <leader>/ :grep <cword> **<cr>
为什么像unite这样的unite映射(我怀疑这是一个unite特定的问题)需要<C-r>=expand('<cword>')<CR>
或<c-r><c-w>
而不是<cword>
?
nnoremap g/ :Unite -input=<C-r>=expand('<cword>')<CR> tag<CR>
最佳答案
像%
这样的特殊字符和<cword>
在:help cmdline-special
下进行了解释.
In Ex commands, at places where a file name can be used, the following characters have a special meaning. These can also be used in the expression function
expand()
.
这解释了为什么 :edit <cword>
有效,但是 :echo "<cword>"
不:后者不带文件名。 :grep
只是模糊地指[arguments]
,但自然其中一些必须是文件。 :Unite
命令是通用的(和自定义的),所以你需要使用 expand()
那里。如有疑问,请尝试一下:-)
关于vim - 在vim中映射<cword>命令时什么时候需要使用expand?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41904905/