vim ag ack

Ag (The Silver Searcher)和 Ack 都是CLI的全局搜索工具,其中Ag更快一些,而Ack也比Vim自带的grep快很多。这些工具的Vim插件可以通过Vim Quickfix窗口来提供代码搜索的结果。 本文便来详细介绍如何在Vim中使用Ag全局搜索。

那么什么是Quickfix窗口呢? Quickfix 是Vim的一个特殊编辑模式,该模式的提出最初是受启发于Aztec C编译器: 把编译错误写入一个文件中,然后从这个文件一一跳转到对应出错的源文件。

安装Ag

Ag是一个命令行工具,用来全局搜索代码文件。 除了速度快之外,还会自动排除 .gitignore.hgignore 里排除的文件。 当然你可以在 agignore 中设置其它要排除的文件。现在来安装它:

# OSX
brew install the_silver_searcher
# Archlinux
pacman -S the_silver_searcher
# Ubuntu
apt-get install silversearcher-ag

装好之后可以在Bash中试试:

ack test_blah ~/code/

安装Ack.vim

Ack.vim 是 Ack 的Vim插件,通过 Quickfix 来提供搜索结果。 但它允许用户定义外部程序,所以我们可以用它来显示 Ag 的搜索结果。

在 ~/.vimrc 中加入:

Plugin 'mileszs/ack.vim'
let g:ackprg = 'ag --nogroup --nocolor --column'

然后运行:

vim +PluginInstall

在运行 PluginInstall 前,需要确保安装了Vundle。 Vundle是Vim插件的包管理工具,可以参见如何用Vim搭建IDE?。

基本使用

然后在Vim中输入 :Ack test_blah 便可以在当前项目代码中搜索 "test_blah" 了。 常用快捷键如下:

?           帮助,显示所有快捷键
Enter/o     打开文件
O           打开文件并关闭Quickfix
go          预览文件,焦点仍然在Quickfix
t           新标签页打开文件
q           关闭Quickfix

可以在 ~/.vimrc 中为 :Ack 设置一个快捷键:

map <c-u> :Ack<space>

以后在普通模式下输入 Ctrl+U 便可以自动输入 :Ack 了。

AG's News Topic Classification Dataset Version 3, Updated 09/09/2015 ORIGIN AG is a collection of more than 1 million news articles. News articles have been gathered from more than 2000 news sources by ComeToMyHead in more than 1 year of activity. ComeToMyHead is an academic news search engine which has been running since July, 2004. The dataset is provided by the academic comunity for research purposes in data mining (clustering, classification, etc), information retrieval (ranking, search, etc), xml, data compression, data streaming, and any other non-commercial activity. For more information, please refer to the link http://www.di.unipi.it/~gulli/AG_corpus_of_news_articles.html . The AG's news topic classification dataset is constructed by Xiang Zhang (xiang.zhang@nyu.edu) from the dataset above. It is used as a text classification benchmark in the following paper: Xiang Zhang, Junbo Zhao, Yann LeCun. Character-level Convolutional Networks for Text Classification. Advances in Neural Information Processing Systems 28 (NIPS 2015). DESCRIPTION The AG's news topic classification dataset is constructed by choosing 4 largest classes from the original corpus. Each class contains 30,000 training samples and 1,900 testing samples. The total number of training samples is 120,000 and testing 7,600. The file classes.txt contains a list of classes corresponding to each label. The files train.csv and test.csv contain all the training samples as comma-sparated values. There are 3 columns in them, corresponding to class index (1 to 4), title and description. The title and description are escaped using double quotes ("), and any internal double quote is escaped by 2 double quotes (""). New lines are escaped by a backslash followed with an "n" character, that is "\n".
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值