sponsor Vim development Vim logo Vim Book Ad

trag : A language & project-aware regexp builder & runner for vimgrep

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

created by
Tom Link
 
script type
utility
 
description
Trag builds regular expressions for vimgrep or its own grep-like function (depending on the task at hand) that allow you to find out where a variable is defined, where it is assigned to another variable, where a method is called etc. At least that's the idea. Since it doesn't use a database it's only suitable for smaller projects -- whatever that means.

First, define which files belong to your project. Most likely your project's source files are already registered in your tags or manifest.txt files, which will be used if available. Alternatively you can set the variable [wbg]:trag_files to a list of files that will be used instead. (Setting this variable will prevent the use of tags.)

Secondly, perform certain operations on these files, like:

    - Select a file to edit
    - Scan/search files for an expression (somewhat like grep)
    - Provide for "modes", i.e. format the regular expression so that
      you can easily search for, e.g., only variable definitions or only
      function calls.


: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.

Suggested maps (best set in ~/vimfiles/after/plugin/trag.vim): >

    noremap <Leader>r. :TRag *
    noremap <Leader>r# :TRag #w <c-r><c-w><cr>
    for c in keys(g:trag_modes)
        exec "nnoremap <Leader>r". c .' :TRag #'. c .' <c-r><c-w><cr>'
        exec "vnoremap <Leader>r". c .' y<esc>:TRag #'. c .' <c-r>"<cr>'
    endfor


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 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.227.156.177

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