Navigating through code is one of the most common tasks a programmer has during his or her daily work. Therefore, anything to speed up this process is a valuable tool for developers. Here, I’m going to show you how to use the powerful ack command.
I think the ack command will be a replacement of grep, at least for developers. This is because grep is a general purpose tool without any optimization for a specific task, such as searching code. Ack uses perl regular expressions by default to improve performance. Ack won’t search on version control directories, non-code files, or minified web files, and can recognize the programming language of the file.
For Mac Users:
$ brew install ack
For Ubuntu users:
$ sudo apt-get ack-grep
Let’s download some code to try ack.
$ git clone https://github.com/neomutt/neomutt.git
You can also be more specific and tell ack what code you are looking for:
$ ack --shell test
The best thing to do is to integrate ack with vim. This is so you can use it in your workflows without leaving vim.
I always recommend using a plugin manager. If you don’t use one, start today. You can follow this article to start: http://xmodulo.com/manage-vim-plugins.html
And if you use one, just check the installation process here: http://vimawesome.com/plugin/ack-vim
The plugin will do the search on the current project. To start a basic search, you must enter on command mode:
You also can immediately open a buffer of the first file matching a pattern:
the_silver_searcher is a “faster ack” according to his author and the benchmark that he shows in the official site: http://geoff.greer.fm/ag/
In case you like this more than ack, you can tell Ack.vim to use it. You just have to add these lines to your .vimrc file:
Vim is one of the most powerful editors available. However, many don’t want to start working with it because of the perceived learning curve, but it’s totally worth it! You will soon thank me and become a vim ninja and code at the speed of light!
Gorilla Logic is always on the hunt for the best software engineers. Think you have what it takes to be a gorilla? Check out our careers section and follow us on Instagram to see what it’s like to be a gorilla.