如何在vim中显示搜索的所有结果 [英] How to display all results of a search in vim

查看:156
本文介绍了如何在vim中显示搜索的所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用记事本++搜索字符串时,新窗口打开并显示查找结果.我想在 vim 中使用这个功能.谷歌搜索后,我发现了一些建议:

When searching string with notepad++, new window opens and shows find results. I want to use this feature in vim. After googling I found out some suggestions:

vimgrep /<pattern>/ %
copen

可以创建执行这两个命令的映射.pattern 应该是当前词:可能是 vim 中的 cword 关键字?

It is possible to create mapping which do those two commands. Pattern should be the current word: may be cword keyword in vim?

推荐答案

这个要求其实很简单.但是要获取用户输入的模式,您需要一个函数.

The requirement is actually easy. but to get user inputted pattern, you need a function.

function! FindAll()
    call inputsave()
    let p = input('Enter pattern:')
    call inputrestore()
    execute 'vimgrep "'.p.'" % |copen'
endfunction

如果你想有一个映射,添加这一行:

if you want to have a mapping, add this line:

nnoremap <F8> :call FindAll()<cr>

但正如我在您的问题下评论的那样.% 可能不适用于未命名的缓冲区.

but as I commented under your question. % may not work for unamed buffer.

这篇关于如何在vim中显示搜索的所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆