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.
gj -i
: build the index.gj main argc argv
: find out the main functions. C/C++ main() typically has these three keywords.example
: keep files with the substring example in the file name.!test
: remove files with the substring test in the file name.1
: Use Vim to edit the first file and jump to the corresponding line.- Exit Vim and back to gj.
2
: Edit the second one.- In Vim,
<leader>G
under DoLogin: list possible definitions or declarations of DoLogin.
gj is based on ID Utils which finds patterns instantly.
Install ID Utils on Debian / Ubuntu with:
sudo apt-get install id-utils
Install gj.vim via Vundle. Please refer documents in Vundle: a highly recommended tool to manage 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"
$ cd /path/to/somewhere/
$ git clone https://github.com/fcamel/gj
$ export PATH="$PATH:`pwd`/bin"
$ cd /path/to/project/
$ gj -i # Build the index.
$ gj PATTERN # Find out PATTERN
Then follow the instructions of output.
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.
- Improve
-d
's speed. - Improve
-d
's accuracy. - Support Emacs as well.
- Add the Vim document.
- Add more screenshots.