vim - VIM 中的 grep 在将结果显示在 vim 中之前打开带有结果的终端

标签 vim grep

我在终端中运行 vim,每当我使用 grep 搜索某些东西时,比如

:grep search_for 文件名

它关闭 vim,在终端中显示结果,并显示“按 Enter 继续”消息,只有在我按 enter 后,它才会在 vim 中显示结果。如何防止这个终端打开并直接在vim中显示结果?

最佳答案

One method将执行以下操作:

function! Grep(...)
    return system(join([&grepprg] + [a:1] + [expandcmd(join(a:000[1:-1], ' '))], ' '))
endfunction

command! -nargs=+ -complete=file_in_path -bar Grep  cgetexpr Grep(<f-args>)
command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep(<f-args>)

cnoreabbrev <expr> grep  (getcmdtype() ==# ':' && getcmdline() ==# 'grep')  ? 'Grep'  : 'grep'
cnoreabbrev <expr> lgrep (getcmdtype() ==# ':' && getcmdline() ==# 'lgrep') ? 'LGrep' : 'lgrep'

augroup quickfix
    autocmd!
    autocmd QuickFixCmdPost cgetexpr cwindow
    autocmd QuickFixCmdPost lgetexpr lwindow
augroup END

这将让您键入 :grep foo 而无需“按 Enter”提示。我建议您阅读 article/gist

关于vim - VIM 中的 grep 在将结果显示在 vim 中之前打开带有结果的终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61361423/

相关文章:

vim - 如何调整 Vim Perl 6 语法高亮以淡化 sigils?

linux - 使用 Linux/Vim 将头文件或文本文件信息转换为代码

unix - 删除基于另一个文件的行

bash - shell编程中的命令 "grep | cut"

linux - 将 grep 搜索从多个文件粘贴到一个新文件

vim - 如何一次关闭所有打开的选项卡?

vim - 调用函数时 Autocmd 未运行执行

linux - 我如何在 Unix 中使用基本的 grep 命令?

需要用于多行搜索的正则表达式(grep)

windows - 在 Windows 中使用 CAPS LOCK 作为 Vim 模式切换键