使用 ack.vim 替代 VIM grep

文章目录

    VIM grep 让人不爽的地方

    • grep 之后,还要输入 :copen,才能看到 quickfix result window
    • quickfix 里的搜索结果,只能在当前窗口打开

    而 ack.vim 很好的解决了这两个痛点

    安装 ack.vim

    Ubuntu 16.10 上首先安装依赖 ack-grep

    sudo apt-get install ack-grep
    

    VIM 上使用 Vundle 安装,现在 .vimrc 中加入

    Plugin 'mileszs/ack.vim
    

    然后打开 VIM, 执行 :PluginInstall

    使用 ack.vim 的高效之处

    可以使用快捷键操作 quickfix result window, 快捷键列表

    ?    a quick summary of these keys, repeat to close
    o    to open (same as Enter)
    O    to open and close the quickfix window
    go   to preview file, open but maintain focus on ack.vim results
    t    to open in new tab
    T    to open in new tab without moving to it
    h    to open in horizontal split
    H    to open in horizontal split, keeping focus on the results
    v    to open in vertical split
    gv   to open in vertical split, keeping focus on the results
    q    to close the quickfix window
    

    禁止自动切换至第一个匹配结果

    If [!] is not given the first error is jumped to.

    :Ack! title -r .
    

    即,在 Ack 后加上 ! 即可。

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式