COLDTURNIP / gj

Search PATTERN in source codes instantly.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gj

Usually we have two needs when reading codes:

  • Find out the definition (or declaration) of foo. foo may be a class, method or a function.
  • Find out all places which use foo.

grep -R foo . is good for the second case since it won't miss any direct use. However, grep is not fast enough for large projects and it's somewhat inconvent for the first case. This is why gj is created.

The goals of gj from high to low are:

  • Low miss: it's bad to miss a caller when you refactor codes or find out who modifies the target variable.
  • Speed: list possible targets instantly.
  • Less reading time: interactively narrow down to your target.

gj is used in two ways:

  • Run as an interactive command line tool to edit and filter candidate files interactively.
  • As a plugin in Vim to find files which containt the word under the cursor.

Demo

Example usage of gj

  1. gj -i: build the index.
  2. gj main argc argv: find out the main functions. C/C++ main() typically has these three keywords.
  3. example: keep files with the substring example in the file name.
  4. !test: remove files with the substring test in the file name.
  5. 1: Use Vim to edit the first file and jump to the corresponding line.
  6. Exit Vim and back to gj.
  7. 2: Edit the second one.
  8. In Vim, <leader>G under DoLogin: list possible definitions or declarations of DoLogin.

Installation

Prerequisite

gj is based on ID Utils which finds patterns instantly.

Install ID Utils on Debian / Ubuntu with:

sudo apt-get install id-utils

Vim Plugin + Command Line Tool

Vundle

Install gj.vim via Vundle. Please refer documents in Vundle: a highly recommended tool to manage vim plugins.

Vim plugins

gj.vim depends on ack.vim, so you need to install ack.vim, too. Add these to your .vimrc:

Bundle 'mileszs/ack.vim'
Bundle 'fcamel/gj'

Then launch vim and run :BundleInstall.

In order to use the command line tool, add this to your $HOME/.bashrc (or other shell config file):

export PATH="$PATH:$HOME/.vim/bundle/gj/bin"

(optional) Command Line Tool Only

$ cd /path/to/somewhere/
$ git clone https://github.com/fcamel/gj
$ export PATH="$PATH:`pwd`/bin"

Usage

Command Line Tool

$ cd /path/to/project/
$ gj -i                 # Build the index.
$ gj PATTERN            # Find out PATTERN

Then follow the instructions of output.

Vim Plugin

In Normal mode:

  • <leader>g Find all matched files of the word under the cursor.
  • <leader>G Find all possible declarations or definitions of the word under the cursor.
  • <leader>d: Find all possible declarations or definitions with a more strongly guess (much less results) of the word under the cursor.

Todo

  • Improve -d's speed.
  • Improve -d's accuracy.
  • Support Emacs as well.
  • Add the Vim document.
  • Add more screenshots.

About

Search PATTERN in source codes instantly.


Languages

Language:Python 71.1%Language:Racket 23.0%Language:Vim Script 5.5%Language:Shell 0.4%