sponsor Vim development Vim logo Vim Book Ad

trag : A language-aware source code scanner (with support for git grep, ack, ag)

 script karma  Rating 7/3, Downloaded by 2381    Comments, bugs, improvements  Vim wiki

created by
Tom Link
 
script type
utility
 
description
This plugin uses ad-hoc searches to find strings in files. For certain
languages, it can also find variable/function/class definitions,
function calls etc.

Other than |tags| or |cscope|, it doesn't build a database to speed up
searches but always scans all files. It can make use of external tools
like `git grep`, `ack`, or `ag` though, in order to gain acceptable
performance for medium-sized projects. The builtin vimscript-based
version file scanner and also |vimgrep| are suitable for small projects.
See |g:trag#grep_type| for available options.


Usage~

First, define which files belong to your project. See
|g:trag#file_sources| for available sources. If the variable contains
"vcs" and the current buffer is under control of a supported VCS, trag
will scan the files in the VCS. Maybe your project's source files are
already registered in your tags files, in which case those will be used.

Secondly, use |:Trag| or |:Traggrep| to scan your project's files. You
can restrict searches to certain "kinds" like only variable definitions
or only function calls. See |trag-kinds| for details.

You can also type <Leader>r# to search for the word under cursor (see
|g:trag_map_leader| and |TragInstallMap()| for details on maps). In
supported filetypes, <Leader>rd will search for the definition of the
word under cursor.

Currently the following filetypes are supported:

    - java
    - javascript
    - json
    - make
    - r
    - ruby
    - viki
    - vim


:Trag[!] MODE REGEXP
    Run |:Tragsearch| and instantly display the result with |:Tragcw|.
    See |trag#Grep()| for help on the arguments.
    Examples:
      " Find any matches
      Trag . foo

      " Find variable definitions (word on the left-hand): foo = 1
      Trag l foo
    
      " Find variable __or__ function/method definitions
      Trag d,l foo
    
      " Find function calls like: foo(a, b)
      Trag f foo
 
install details
Edit the vba file and type: >

    :so %

See :help vimball for details. If you have difficulties or use vim 7.0,
please make sure, you have the current version of vimball
(vimscript #1502) installed.

This script requires tlib (vimscript #1863) to be installed.

Also available via git
http://github.com/tomtom/trag_vim
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
trag.vba 1.01 2014-07-07 7.0 Tom Link - trag#utils#GrepaddFiles(): Use shellescape(..., 1)
- g:trag#debug: Hide warnings by default
- Make sure not to run git grep on files outside of the repo (use trag instead; require tlib 0.112)
- Minor improvements; g:trag#grep_fallback_type
- GrepWith_external(): bufnr optimization
- GrepWith_external(): normalize filenames
- ag: Don't use -Q for "identity"
MD5 checksum: 3c5f2c7653a0345612891fe614655997
trag.vba 1.00 2014-07-05 7.0 Tom Link - addon-info
- <c-l> Edit line
- Help template
- trag#RunCmdOnSelected(): Optionally use w.GetBufferLines() if provided (see vikitasks #104b45b)
- trag#RunCmdOnSelected(): Preliminary support for w.AfterRunCmd()
- trag#Grep(): Takes filetype as second optional argument
- g:trag#grep_type replaces g:trag_search_mode
- g:trag_map_leader, TragInstallMap(), TragInstallKindMap(): Make it easier to set up maps
- trag#GetGitFiles(): Use g:tlib#dir#sep, not the obsolete g:tlib_filename_sep
- Rename most commands matching TRag* -> Trag*
- trag#SetRepoFiles(): Use files in current VCS repo
- trag#Grep(): Refactor to enable use of external grep commands
- s:GetRx(): Return [posrx, filetype]
- First draft for use of external grep
- vim: Use :grepadd
- Further improvements to allow use of external grep commands
- Initial support for VCS (e.g. git grep)
- g:trag#file_sources: Define source for file lists
- trag#external#vcs#Run(): Use fnameescape()
- Fixed some regexps
- Rename s:trag_filenames to g:trag_extension_filetype
- TRagDefKind: accepts an optional "!"
- g:trag#file_sources can be buffer-local (b:trag_file_sources)
- Remove references to trag#Process_*
- trag#GetGitFiles(): Use \%()
- trag#external#grep#IsSupported(): Minor simplification
- trag#external#vcs#Run(): Minor optimization
- trag#DefFiletype()
- trag#external#vcs#Run(): Use
- Move filetype definitions to ftplugin/*/trag.vim
- json support
- FIX javascript regexp
- Use viki for *.TXT
- Draft for "hg grep" support (currently disabled due to poor performance)
- rx.vim: Convert regexps
- trag#utils#GrepaddFiles(): Process files in batches
- Adapt vcs to previous changes
- Improved support for grep
- Support for ack
- b:trag_grep_type: Buffer-local g:trag#grep_type
- GrepWith_grep, GrepWith_ack
- g:trag#file_sources: tags support
- Rename g:trag#external#ack#ack_params to g:trag#external#ack#opts
- Support for ag (the_silver_searcher)
- FIX javascript l regexp
- g:trag_kinds_ignored_comments: A list of kinds for which |TragInstallKindMap()| will install maps that ignore comments
- New kind: "u" (uses of word; ignore comments)
- trag#utils#GrepaddFiles(): Escape "()" in filenames
- trag#rx#ConvertRx_perl(): Handle \{-}, \+, \?
- trag#utils#GrepaddFiles(): Use shellescape()
- Support for Makefiles
MD5 checksum: c87df75189cfb7574a10ba093bf60a0a
trag.vba 0.11 2012-09-28 7.0 Tom Link - trag#LocList(): Take world & suspended as arguments (like #BrowseList())
- Be more clever at guessing the filetype (allow filenames as patterns)
- No direct external access to trag_filenames
- g:trag#check_vcs: If the file is under a VCS, scan through all files in the VCS (requires tlib 0.44)
- trag#AgentWithSelected(): cmd as optional argument
- s:DoAutoCmd(): call event only if one is defined
- Show item in balloon (if available)
- trag#RunCmdOnSelected(): Optional argument: Don't close scratch
MD5 checksum: e4bc34f9c3ef3ce134f2c41918d0922d
trag.vba 0.09 2012-01-21 7.0 Tom Link - Don't hide the window if all error numbers are -1
- .gitignore
- trag#Grep(): trigger QuickFixCmdPre & QuickFixCmdPost events for "trag"
- trag#LocList() used qfl
MD5 checksum: 255a58b855b4e21462b517826c88fd91
trag.vba 0.8 2010-03-31 7.0 Tom Link - Moved the definition of some variables from plugin/trag.vim to autoload/trag.vim
- :TRagcw! (show :cw even if there are no recognized errors)
- Require tlib 0.37
trag.vba.gz 0.7 2009-12-21 7.0 Tom Link - trag#QuickList(): Accept a dict as optional argument.
- trag#Grep(): rx defaults to '\.{-}'
- trag#Grep(): use :g (instead of search()) for non-vimgrep mode
trag.vba.gz 0.6 2009-10-18 7.0 Tom Link - trag#viki#Rename()
- Generalized trag#rename#Rename()
- Enabled "trace cursor" functionality (mapped to the <c-insert> key).
- :Traglw
- TRagGitFiles, trag#SetGitFiles(), g:trag_git
trag.vba.gz 0.5 2009-02-25 7.0 Tom Link - Update the qfl when running a command on selected lines
- Enable certain operations for multiple choices
- Java, Ruby: x ... find subclasses (extends/implements)
- Experimental rename command for refactoring (general, java)
- NEW: [bg]:trag_get_files_{&filetype}
- Traggrep: If the second argument (glob pattern) is missing, the
default file list will be used.
trag.vba.gz 0.4 2008-11-22 7.0 Tom Link - trag_proj* variables were renamed to trag_project*.
- Traggrep: Arguments have changed for conformity with grep commands (an implicit .-argument is prepended)
- Make sure tlib is loaded even if it is installed in a different rtp-directory.
- Post-process lines (strip whitespace) collected by vimgrep
- tlib#Edit(): for list input, set pick_last_item=0, show_empty=1
- Aliases for some commands: Trag, Traggrep ...
trag.vba.gz 0.3 2008-02-26 7.0 Tom Link - Use vimgrep with set ei=all as default search mode (can be configured via g:trag_search_mode); by default trag now is a wrapper around vimgrep that does the handling of project-related file-sets and regexp builing for you.
- FIX: ruby/f regexp
trag.vba.gz 0.2 2008-02-19 7.0 Tom Link - Quite a few things have changed and I haven't had the time yet to test
these changes thorougly. There is a chance that nested patterns thus
don't work as described (please report).
- Enable search for more than one kinds at once (as comma-separated
list)
- Enabled <c-e>: Run ex-command on selected lines (e.g. for refactoring
purposes)
- Enabled <c-s>, <c-v>, <c-t>: Open selected lines in (vertically) split
windows or tabs.
- Renamed vV kinds to lL (~ let)
- New kind: r/R (right hand side argument of an assignment/let, i.e.
value)
- New kind: fuzzy (typo-tolerant search)
- INCOMPATIBLE CHANGE: Renamed "mode" to "kind"
- TRag now has some idea of negation. E.g., "TRag !i,w call" will search
for the word "call" but ignore matches in comments (if defined for the
    current filetype)
- Alternative methods to define project files: g:trag_files,
g:trag_glob, g:trag_proj.
- Improved support for ruby, vim
- TRagKeyword, trag#CWord(): Customize keyword rx.
- g:trag_get_files
- [bg]:trag_proj_{&filetype}: Name of the filetype-specific project
files catalog (overrides [bg]:trag_proj if defined)
- trag#Edit() will now initally select files with the same "basename
root" (^\w\+) as the current buffer (the command is thus slightly more
useful and can be used as an ad-hoc alternative file switcher)
- FIX: Match a line only once
- FIX: Caching of regexps
trag.vba.gz 0.1 2007-09-30 7.0 Tom Link Initial upload
ip used for rating: 54.211.180.175

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo