" Vimball Archiver by Charles E. Campbell, Jr., Ph.D. UseVimball finish doc/trag.txt [[[1 757 *trag.txt* A language-aware source code scanner (with support for git grep, ack, ag, sift ...) Author: Tom Link, micathom at gmail com 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 the following external tools in order to gain acceptable performance for medium-sized projects: - `git grep` - `ack` http://beyondgrep.com/ - `ag` https://github.com/ggreer/the_silver_searcher - `sift` https://sift-tool.org/ 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| 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 r# to search for the word under cursor (see |g:trag_map_leader| and |TragInstallMap()| for details on maps). In supported filetypes, 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 Run `:echo globpath(&rtp, 'ftplugin/*/trag.vim')` to get a full listing of supported filetypes. NOTE: Some kinds are available only for a subset of known filetypes. Default maps: r# ... Trag the word under cursor r. ... :Trag command-line r+ ... Show quickfixlist via |:Tragcw| r* ... Edit a file from the files list, i.e. the list that would be used if no "--file_sources" argument were passed to |:Trag| rx ... The same as `:Trag -l -i=x -x=i ` where x is a alphabetical letter that describes a kind in |g:trag_kinds| and is the word under cursor. "-x=i" (exclude commented text) is only added if kind x is in |g:trag_kinds_ignored_comments|. ----------------------------------------------------------------------- Install~ 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. ----------------------------------------------------------------------- *trag-kinds* Kinds~ Certain commands take a "kind" as argument. A "kind" in the context of trag means a way how the expression is interpreted and (in the future) how the lines are scanned. The meaning of the letter is specific for a certain filetype. In general, the following list should serve as a common base: c ... class definitions d ... function/method definitions f ... function calls i ... ignored lines, comments etc. l ... variable definition m ... module definitions r ... variable assignment (e.g. "= WORD") u ... uses of word (ignore comments) w ... find as word x ... subclasses fuzzy ... use a typo-tolerant regexp todo ... TODO markers etc. EXPERIMENTAL: Kinds can be joined as comma-separated list (OR) of period-seprated list (CONTAIN). This may be unintuitive but that's the way it is. Order in CONTAIN-patterns matters, i.e. w.i doesn't make too much sense (a word that CONTAINs a comment, which could only be the word itself) but i.w does (a comment that CONTAINs a word, which is quite possible). The available command-line options are documented in |:Trag|. These command-line options allow users to defined which lines should be matched. Example: -i=l,r ...... a word either on the left OR right hand side of an assignment -x=i ........ match lines that are not comments -i=w -x=i ... word that is NOT contained in a comment More examples: File contents: > #1 function Foo() {} #2 function FooBar() {} #3 let x = FooBar() #4 let x = Foo() < :TRag Foo => Find "Foo": 1-4 :TRag -i=w Foo => Find the __w__ords "Foo": 1, 4 :TRag -i=d Foo => Find __d__efinitions of "Foo": 1, 2 :TRag -i=d.w Foo => Find __d__efinitions of the __w__ord "Foo": 1 :TRag -i=f Foo => Find (__f__unction) calls of "Foo": 3, 4 :TRag -i=f.w Foo => Find (__f__unction) calls of the __w__ord "Foo": 4 Not every kind is defined for every filetype. Currenty, support for the following filetype(s) is somewhat above average: - ruby - vim Use |:TRagDefKind| to define new kinds. See |trag#Grep()| for details of how to use this. ======================================================================== Contents~ g:trag_map_leader ....................... |g:trag_map_leader| g:trag_kinds_ignored_comments ........... |g:trag_kinds_ignored_comments| :TRagDefKind ............................ |:TRagDefKind| :TRagKeyword ............................ |:TRagKeyword| :TRagDefFiletype ........................ |:TRagDefFiletype| :Trag ................................... |:Trag| :Tragcw ................................. |:Tragcw| :Traglw ................................. |:Traglw| :Tragfiles .............................. |:Tragfiles| TragInstallMap .......................... |TragInstallMap()| TragInstallKindMap ...................... |TragInstallKindMap()| trag#general#Rename ..................... |trag#general#Rename()| trag#viki#Rename ........................ |trag#viki#Rename()| trag#rename#Rename ...................... |trag#rename#Rename()| prototype.Get_files prototype.Get_grep_defs prototype.Get_group_defs prototype.Get_must_filter trag#grepdefs#New ....................... |trag#grepdefs#New()| trag#grepdefs#GetGrepDef ................ |trag#grepdefs#GetGrepDef()| trag#grepdefs#ClearCachedRx ............. |trag#grepdefs#ClearCachedRx()| g:trag#external#ack#opts ................ |g:trag#external#ack#opts| g:trag#external#ack#supported_kinds ..... |g:trag#external#ack#supported_kinds| trag#external#ack#IsSupported ........... |trag#external#ack#IsSupported()| trag#external#ack#Run ................... |trag#external#ack#Run()| g:trag#external#sift#ignore_dirs ........ |g:trag#external#sift#ignore_dirs| g:trag#external#sift#opts ............... |g:trag#external#sift#opts| g:trag#external#sift#supported_kinds .... |g:trag#external#sift#supported_kinds| trag#external#sift#IsSupported .......... |trag#external#sift#IsSupported()| trag#external#sift#Run .................. |trag#external#sift#Run()| g:trag#external#vcs#options_git ......... |g:trag#external#vcs#options_git| g:trag#external#vcs#supported_kinds ..... |g:trag#external#vcs#supported_kinds| trag#external#vcs#IsSupported ........... |trag#external#vcs#IsSupported()| trag#external#vcs#Run ................... |trag#external#vcs#Run()| trag#external#vcs#ConvertFilename_git ... |trag#external#vcs#ConvertFilename_git()| g:trag#external#ag#opts ................. |g:trag#external#ag#opts| g:trag#external#ag#supported_kinds ...... |g:trag#external#ag#supported_kinds| trag#external#ag#IsSupported ............ |trag#external#ag#IsSupported()| trag#external#ag#Run .................... |trag#external#ag#Run()| g:trag#external#grep#args ............... |g:trag#external#grep#args| g:trag#external#grep#supported_kinds .... |g:trag#external#grep#supported_kinds| trag#external#grep#IsSupported .......... |trag#external#grep#IsSupported()| trag#external#grep#Run .................. |trag#external#grep#Run()| trag#rx#ConvertRx ....................... |trag#rx#ConvertRx()| trag#rx#ConvertRx_git ................... |trag#rx#ConvertRx_git()| trag#rx#ConvertRx_perl .................. |trag#rx#ConvertRx_perl()| g:trag#utils#cmdline_max ................ |g:trag#utils#cmdline_max| trag#utils#GrepaddFiles ................. |trag#utils#GrepaddFiles()| trag#java#Rename ........................ |trag#java#Rename()| g:trag#extension_filetype ............... |g:trag#extension_filetype| g:trag#grep_type ........................ |g:trag#grep_type| g:trag#assume_executable ................ |g:trag#assume_executable| g:trag#grep_fallback_type ............... |g:trag#grep_fallback_type| g:trag_get_files ........................ |g:trag_get_files| g:trag_get_files_java ................... |g:trag_get_files_java| g:trag_get_files_c ...................... |g:trag_get_files_c| g:trag_get_files_cpp .................... |g:trag_get_files_cpp| g:trag#file_sources ..................... |g:trag#file_sources| g:trag#use_buffer ....................... |g:trag#use_buffer| g:trag#check_vcs ........................ |g:trag#check_vcs| g:trag#debug ............................ |g:trag#debug| g:trag#world ............................ |g:trag#world| trag#HasFiletype ........................ |trag#HasFiletype()| trag#SetFiletype ........................ |trag#SetFiletype()| trag#GetFiletype ........................ |trag#GetFiletype()| g:trag_files ............................ |g:trag_files| g:trag_glob ............................. |g:trag_glob| g:trag_project_ruby ..................... |g:trag_project_ruby| g:trag_project .......................... |g:trag_project| g:trag_git .............................. |g:trag_git| trag#GetProjectFiles .................... |trag#GetProjectFiles()| trag#GetGitFiles ........................ |trag#GetGitFiles()| trag#Edit ............................... |trag#Edit()| trag#Grep ............................... |trag#Grep()| trag#GrepWithArgs ....................... |trag#GrepWithArgs()| trag#ScanWithGrepDefs ................... |trag#ScanWithGrepDefs()| trag#QuickList .......................... |trag#QuickList()| trag#QuickListMaybe ..................... |trag#QuickListMaybe()| trag#BrowseList ......................... |trag#BrowseList()| trag#LocList ............................ |trag#LocList()| trag#AgentRefactor ...................... |trag#AgentRefactor()| trag#CWord .............................. |trag#CWord()| trag#RefactorRename ..................... |trag#RefactorRename()| trag#IsSupported ........................ |trag#IsSupported()| trag#CComplete .......................... |trag#CComplete()| ======================================================================== plugin/trag.vim~ *g:trag_map_leader* g:trag_map_leader (default: 'r') Trag map leader. See also |TragInstallMap()|. *g:trag_kinds_ignored_comments* g:trag_kinds_ignored_comments (default: ['c', 'd', 'f', 'l', 'r', 'u']) A list of kinds for which |TragInstallKindMap()| will install maps that ignore comments. *:TRagDefKind* :TRagDefKind[!] KIND FILETYPE /REGEXP_FORMAT/ The regexp argument is no real regexp but a format string. % thus have to be escaped with % (see |printf()| for details). The REGEXP_FORMAT should contain at least one %s. With the [!], reset the regexp definitions. Examples: > TRagDefKind v * /\C\<%s\>\s*=[^=~<>]/ TRagDefKind v ruby /\C\<%s\>\(\s*,\s*[[:alnum:]_@$]\+\s*\)*\s*=[^=~<>]/ < *:TRagKeyword* TRagKeyword FILETYPE KEYWORD_CHARS Override 'iskeyword' for a certain filetype. See also |trag#CWord()|. *:TRagDefFiletype* TRagDefFiletype FILETYPE /REGEXP/ ... EXTENSION ... FILENAME ... In order to recognize files based on their extension, you have to declare filetypes first. If a file has no extension, the whole filename is used. On systems where the case of the filename doesn't matter (check :echo has('fname_case')), EXTENSION should be defined in lower case letters. Examples: > TRagDefFiletype html html htm xhtml < *:Trag* :Trag[!] [ARGS] [REGEXP] [GLOBPATTERN] Scan the files registered in your tag files for REGEXP. Generate a quickfix list. With [!], append to the given list. The quickfix list can be viewed with commands like |:cw| or |:Tragcw|. The REGEXP has to match a single line. This uses |readfile()| and the scans the lines. This is an alternative to |:vimgrep|. If you choose your identifiers wisely, this should guide you well through your sources. Supported command-line options for ARGS: -i=KINDS, --include=KINDS ... Include KINDS (default: .) -x=KINDS, --exclude=KINDS ... Exclude KINDS -A=REGEXP, --accept=REGEXP .. Include files matching REGEXP -R=REGEXP, --reject=REGEXP .. Exclude files matching REGEXP --filetype=FILETYPE ......... Assume 'filetype' is FILETYPE -l, --literal ............... RX is a literal text, not a |regexp| --grep_type=GREP_TYPE ....... See |g:trag#grep_type| --file_sources=SOURCES ...... A comma-separated list of sources (see |g:trag#file_sources|) --filenames ................. Include matching filenames --no-text ................... Don't include matching text lines --glob=PATTERN .............. Pattern for "glob" source --force ..................... Don't use cached information --cw=CMD .................... Command to use for displaying the result (default: :Tragcw; use "none" in order not to display the results list) Positional arguments: REGEXP ...................... A |regexp| or text (see --literal) GLOB PATTERNS ............... Optional |glob| patterns If the kind rx doesn't contain %s (e.g. todo), you can skip the regexp. Examples: > " Find any matches Trag foo " Find variable definitions (word on the left-hand): foo = 1 Trag -i=l foo " Find variable __or__ function/method definitions Trag -i=d,l foo " Find function calls like: foo(a, b) Trag -i=f foo " Find TODO markers Trag -i=todo < *:Tragcw* :Tragcw Display a quick fix list using |tlib#input#ListD()|. *:Traglw* :Traglw Display a |location-list| using |tlib#input#ListD()|. *:Tragfiles* :Tragfiles Edit a file registered in your tag files. *TragInstallMap()* TragInstallMap(leader) Install the following maps: # ........ Search word under cursor . ........ :Trag * The following maps might be defined only after the first invocation: ... Search word under cursor of KIND See |g:trag_kinds| E.g. d searches for the definition of the word under cursor. *TragInstallKindMap()* TragInstallKindMap(leader, kind) ======================================================================== autoload/trag/general.vim~ *trag#general#Rename()* trag#general#Rename(world, selected, rx, subst) ======================================================================== autoload/trag/viki.vim~ *trag#viki#Rename()* trag#viki#Rename(world, selected, from, to) ======================================================================== autoload/trag/rename.vim~ *trag#rename#Rename()* trag#rename#Rename(world, selected, from, to, suffix) ======================================================================== autoload/trag/grepdefs.vim~ prototype.Get_files prototype.Get_grep_defs prototype.Get_group_defs prototype.Get_must_filter *trag#grepdefs#New()* trag#grepdefs#New(files, kindspos, kindsneg, rx, filetype) *trag#grepdefs#GetGrepDef()* trag#grepdefs#GetGrepDef(filename, kindspos, kindsneg, rx, filetype) *trag#grepdefs#ClearCachedRx()* trag#grepdefs#ClearCachedRx() ======================================================================== autoload/trag/external/ack.vim~ *g:trag#external#ack#opts* g:trag#external#ack#opts (default: {'grepprg': 'ack', 'args': '-Hns --nocolor --nogroup %s --'}) *g:trag#external#ack#supported_kinds* g:trag#external#ack#supported_kinds (default: ['identity', 'u', 'w', 'todo']) *trag#external#ack#IsSupported()* trag#external#ack#IsSupported(kinds) *trag#external#ack#Run()* trag#external#ack#Run(kinds, rx, files) ======================================================================== autoload/trag/external/sift.vim~ *g:trag#external#sift#ignore_dirs* g:trag#external#sift#ignore_dirs (default: ['.git', '.hg']) *g:trag#external#sift#opts* g:trag#external#sift#opts (default: {'grepprg': 'sift', 'args': '--exclude-dirs DIRS --no-color -n -- %s'}) "--exclude-dirs DIRS" will be replaced with the entries from |g:trag#external#sift#ignore_dirs|. *g:trag#external#sift#supported_kinds* g:trag#external#sift#supported_kinds (default: ['identity', 'u', 'w', 'todo']) *trag#external#sift#IsSupported()* trag#external#sift#IsSupported(kinds) *trag#external#sift#Run()* trag#external#sift#Run(kinds, rx, files) ======================================================================== autoload/trag/external/vcs.vim~ *g:trag#external#vcs#options_git* g:trag#external#vcs#options_git (default: {'args': 'grep -Hn -G %s --'}) *g:trag#external#vcs#supported_kinds* g:trag#external#vcs#supported_kinds (default: ['identity', 'w', 'todo']) *trag#external#vcs#IsSupported()* trag#external#vcs#IsSupported(kinds) *trag#external#vcs#Run()* trag#external#vcs#Run(kinds, rx, files) Currently only git is supported. For other VCSs, I'd recommend to use "ag". *trag#external#vcs#ConvertFilename_git()* trag#external#vcs#ConvertFilename_git(type, filename) ======================================================================== autoload/trag/external/ag.vim~ *g:trag#external#ag#opts* g:trag#external#ag#opts (default: {'grepprg': 'ag', 'args': '-U -f --line-numbers --nogroup --nocolor -- %s'}) *g:trag#external#ag#supported_kinds* g:trag#external#ag#supported_kinds (default: ['identity', 'u', 'w', 'todo']) *trag#external#ag#IsSupported()* trag#external#ag#IsSupported(kinds) *trag#external#ag#Run()* trag#external#ag#Run(kinds, rx, files) ======================================================================== autoload/trag/external/grep.vim~ *g:trag#external#grep#args* g:trag#external#grep#args (default: '-Hn -E %s --') *g:trag#external#grep#supported_kinds* g:trag#external#grep#supported_kinds (default: ['identity', 'u', 'w', 'todo']) *trag#external#grep#IsSupported()* trag#external#grep#IsSupported(kinds) *trag#external#grep#Run()* trag#external#grep#Run(kinds, rx, files, ...) ======================================================================== autoload/trag/rx.vim~ *trag#rx#ConvertRx()* trag#rx#ConvertRx(rx, type, ...) *trag#rx#ConvertRx_git()* trag#rx#ConvertRx_git(type, rx) *trag#rx#ConvertRx_perl()* trag#rx#ConvertRx_perl(type, rx) ======================================================================== autoload/trag/utils.vim~ *g:trag#utils#cmdline_max* g:trag#utils#cmdline_max (default: g:tlib#sys#windows ? 7000 : 100000) *trag#utils#GrepaddFiles()* trag#utils#GrepaddFiles(args, files) ======================================================================== autoload/trag/java.vim~ *trag#java#Rename()* trag#java#Rename(world, selected, from, to) ======================================================================== autoload/trag.vim~ *g:trag#extension_filetype* g:trag#extension_filetype (default: {}) A dictionary FILENAME_EXTENSION => FILETYPE On systems without has('fname_case') (see |feature-list|), FILENAME_EXTENSION should be a lower-case string. *g:trag#grep_type* g:trag#grep_type (default: 'trag') A comma-separated list of preferred grep programs: - trag - vimgrep - vcs (use the VCS's grep function; see |trag#external#vcs#Run()|, this option always searches all files in the VCS); for a list of supported VCSs see |trag#external#vcs#Run()| - external:CMD (CMD defaults to grep; use vimgrep as fallback) - ack (https://github.com/petdance/ack2) - ag (https://github.com/ggreer/the_silver_searcher) - grep (uses 'grepprg') The first valid option is used. E.g. if the value is "vcs,trag" and if the buffer belongs to a supported VCS (see |trag#external#vcs#Run()|, the VCS's grep function is used. Otherwise trag's own version of grep is used. trag & vimgrep should work everywhere. *b:trag_grep_type* b:trag_grep_type overrides this global variable. *g:trag#assume_executable* g:trag#assume_executable (default: ['vcs']) *g:trag#grep_fallback_type* g:trag#grep_fallback_type (default: 'trag') Use this type for files that are not supported by |g:trag#grep_type| (e.g. files outside of a VCS if |g:trag#grep_type| includes "vcs"). *g:trag_get_files* g:trag_get_files (default: 'split(glob("*"), "\n")') If no project files are defined, evaluate this expression as fallback-strategy. *g:trag_get_files_java* g:trag_get_files_java (default: 'split(glob("**/*.java"), "\n")') *g:trag_get_files_c* g:trag_get_files_c (default: 'split(glob("**/*.[ch]"), "\n")') *g:trag_get_files_cpp* g:trag_get_files_cpp (default: 'split(glob("**/*.[ch]"), "\n")') *g:trag#file_sources* g:trag#file_sources (default: ['vcs', 'project', 'files', 'glob', 'tags', 'filetype', 'buffer']) A list of sources. Possible values: vcs ....... Use g:trag#check_vcs git ....... Use b:trag_git or g:trag_git tags ...... Use files listed in 'tags' files ..... Use b:trag_files or g:trag_files glob ...... Use b:trag_glob or g:trag_glob project ... Use b:trag_project_{'filetype'} or g:trag_project_{'filetype'} buffer .... Use the current buffer's directory cd ........ Use the current working directory (see |getcwd()|) *FN ....... Call function FN with one arg (a dictionary of options) *b:trag_file_sources* b:trag_file_sources overrides this global variable. *g:trag#use_buffer* g:trag#use_buffer (default: 1) If true, use an already loaded buffer instead of the file on disk in certain situations. This implies that if a buffer is dirty, the non-saved version in memory will be preferred over the version on disk. *g:trag#check_vcs* g:trag#check_vcs (default: 1) If true, try to detect whether the current file is under an VCS and use that later on. *g:trag#debug* g:trag#debug (default: 0) *g:trag#world* g:trag#world (default: {) *trag#HasFiletype()* trag#HasFiletype(name) Return true, if a filetype for "name" (an extension or a filename) is defined. *trag#SetFiletype()* trag#SetFiletype(filetype, name) Define that filenames ("name" can be either an extension or a filename) are of a certain filetype. *trag#GetFiletype()* trag#GetFiletype(name) Get the filetype for "name" (either an extension of a filename). The following variables provide alternatives to collecting your project's file list on the basis of you tags files. These variables are tested in the order as listed here. If the value of a variable is non-empty, this one will be used instead of the other methods. The tags file is used as a last ressort. *g:trag_files* g:trag_files (default: []) 1. A list of files. Can be buffer local. *g:trag_glob* g:trag_glob (default: '') 2. A glob pattern -- this should be an absolute path and may contain ** (see |glob()| and |wildcards|). Can be buffer local. *g:trag_project_ruby* g:trag_project_ruby (default: 'Manifest.txt') 3. Filetype-specific project files. *g:trag_project* g:trag_project (default: '') 4. The name of a file containing the projects file list. This file could be generated via make. Can be buffer local. *g:trag_git* g:trag_git (default: '') 5. The name of a git repository that includes all files of interest. If the value is "*", trag will search from the current directory (|getcwd()|) upwards for a .git directory. If the value is "finddir", use |finddir()| to find a .git directory. Can be buffer local. *trag#GetProjectFiles()* trag#GetProjectFiles(manifest) *trag#GetGitFiles()* trag#GetGitFiles(repos) *trag#Edit()* trag#Edit() Edit a file from the project catalog. See |g:trag_project| and |:TRagfile|. *trag#Grep()* trag#Grep(args, ?replace=1, ?files=[], ?filetype='') args: A string with the format: KIND REGEXP KIND1,KIND2 REGEXP DEPRECATED: Old syntax. Please use |trag#GrepWithArgs()| instead. If the variables [bg]:trag_rxf_{kind}_{&filetype} or [bg]:trag_rxf_{kind} exist, these will be taken as format string (see |printf()|) to format REGEXP. EXAMPLE: trag#Grep('v foo') will find by default take g:trag_rxf_v and find lines that looks like "\\s*=[^=~]", which most likely is a variable definition in many programming languages. I.e. it will find lines like: > foo = 1 < but not: > def foo(bar) call foo(bar) if foo == 1 < *trag#GrepWithArgs()* trag#GrepWithArgs(args, ?replace=1, ?extra={}) args is a list of strings of command-line arguments of |:Trag|. If the variables [bg]:trag_rxf_{kind}_{&filetype} or [bg]:trag_rxf_{kind} exist, these will be taken as format string (see |printf()|) to format REGEXP. *trag#ScanWithGrepDefs()* trag#ScanWithGrepDefs(grep_def, lines, setqflist) *trag#QuickList()* trag#QuickList(?world={}, ?suspended=0) Display the |quickfix| list with |tlib#input#ListW()|. *trag#QuickListMaybe()* trag#QuickListMaybe(anyway) *trag#BrowseList()* trag#BrowseList(world_dict, list, ...) *trag#LocList()* trag#LocList(...) Display the |location-list| with |tlib#input#ListW()|. *trag#AgentRefactor()* trag#AgentRefactor(world, selected) Invoke an refactor command. Currently only one command is supported: rename *trag#CWord()* trag#CWord() *trag#RefactorRename()* trag#RefactorRename(world, selected) *trag#IsSupported()* trag#IsSupported(supported_kinds, kinds) *trag#CComplete()* trag#CComplete(ArgLead, CmdLine, CursorPos) vim:tw=78:fo=w2croql:isk=!-~,^*,^|,^":ts=8:ft=help:norl: plugin/trag.vim [[[1 174 " trag.vim -- Jump to a file registered in your tags " @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Website: http://www.vim.org/account/profile.php?user_id=4037 " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Created: 2007-09-29. " @Last Change: 2015-11-07. " @Revision: 733 " GetLatestVimScripts: 2033 1 trag.vim if &cp || exists("g:loaded_trag") finish endif let g:loaded_trag = 200 let s:save_cpo = &cpo set cpo&vim " :nodoc: TLet g:trag_kinds = {} " :nodoc: TLet g:trag_keyword_chars = {} " Trag map leader. See also |TragInstallMap()|. TLet g:trag_map_leader = 'r' " A list of kinds for which |TragInstallKindMap()| will install maps " that ignore comments. TLet g:trag_kinds_ignored_comments = ['c', 'd', 'f', 'l', 'r', 'u'] " :display: :TRagDefKind[!] KIND FILETYPE /REGEXP_FORMAT/ " The regexp argument is no real regexp but a format string. % thus have " to be escaped with % (see |printf()| for details). The REGEXP_FORMAT " should contain at least one %s. " " With the [!], reset the regexp definitions. " " Examples: > " TRagDefKind v * /\C\<%s\>\s*=[^=~<>]/ " TRagDefKind v ruby /\C\<%s\>\(\s*,\s*[[:alnum:]_@$]\+\s*\)*\s*=[^=~<>]/ command! -bang -nargs=1 TRagDefKind call trag#TragDefKind(, !empty("")) " :display: TRagKeyword FILETYPE KEYWORD_CHARS " Override 'iskeyword' for a certain filetype. See also |trag#CWord()|. command! -nargs=+ TRagKeyword if len([]) == 2 \ | let g:trag_keyword_chars[[][0]] = [][1] \ | else \ | echoerr 'Expected "FILETYPE KEYWORDRX", but got: ' \ | endif " :display: TRagDefFiletype FILETYPE /REGEXP/ ... EXTENSION ... FILENAME ... " In order to recognize files based on their extension, you have to " declare filetypes first. " If a file has no extension, the whole filename is used. " On systems where the case of the filename doesn't matter (check :echo " has('fname_case')), EXTENSION should be defined in lower case letters. " Examples: > " TRagDefFiletype html html htm xhtml command! -nargs=+ TRagDefFiletype call trag#DefFiletype([]) " :display: :Trag[!] [ARGS] [REGEXP] [GLOBPATTERN] " Scan the files registered in your tag files for REGEXP. Generate a " quickfix list. With [!], append to the given list. The quickfix list " can be viewed with commands like |:cw| or |:Tragcw|. " " The REGEXP has to match a single line. This uses |readfile()| and the " scans the lines. This is an alternative to |:vimgrep|. " If you choose your identifiers wisely, this should guide you well " through your sources. " " Supported command-line options for ARGS: " " -i=KINDS, --include=KINDS ... Include KINDS (default: .) " -x=KINDS, --exclude=KINDS ... Exclude KINDS " -A=REGEXP, --accept=REGEXP .. Include files matching REGEXP " -R=REGEXP, --reject=REGEXP .. Exclude files matching REGEXP " --filetype=FILETYPE ......... Assume 'filetype' is FILETYPE " -l, --literal ............... RX is a literal text, not a |regexp| " --grep_type=GREP_TYPE ....... See |g:trag#grep_type| " --file_sources=SOURCES ...... A comma-separated list of sources (see " |g:trag#file_sources|) " --filenames ................. Include matching filenames " --no-text ................... Don't include matching text lines " --glob=PATTERN .............. Pattern for "glob" source " --force ..................... Don't use cached information " --cw=CMD .................... Command to use for displaying the " result (default: :Tragcw; use "none" " in order not to display the results " list) " " Positional arguments: " REGEXP ...................... A |regexp| or text (see --literal) " GLOB PATTERNS ............... Optional |glob| patterns " " If the kind rx doesn't contain %s (e.g. todo), you can skip the " regexp. " " Examples: > " " Find any matches " Trag foo " " " Find variable definitions (word on the left-hand): foo = 1 " Trag -i=l foo " " " Find variable __or__ function/method definitions " Trag -i=d,l foo " " " Find function calls like: foo(a, b) " Trag -i=f foo " " " Find TODO markers " Trag -i=todo command! -nargs=+ -bang -bar -complete=customlist,trag#CComplete Trag call trag#GrepWithArgs([], empty("")) " :display: :Tragcw " Display a quick fix list using |tlib#input#ListD()|. command! -bang -nargs=? Tragcw call trag#QuickListMaybe(!empty("")) " :display: :Traglw " Display a |location-list| using |tlib#input#ListD()|. command! -nargs=? Traglw call trag#LocList() " :display: :Tragfiles " Edit a file registered in your tag files. command! Tragfiles call trag#Edit() " Install the following maps: " " # ........ Search word under cursor " . ........ :Trag * " " The following maps might be defined only after the first invocation: " " ... Search word under cursor of KIND " See |g:trag_kinds| " " E.g. d searches for the definition of the word under " cursor. function! TragInstallMap(leader) "{{{3 " TLogVAR a:leader exec 'noremap' a:leader .'. :Trag ' exec 'noremap' a:leader .'+ :Tragcw' exec 'noremap' a:leader .'* :Tragfiles' exec 'noremap ' a:leader .'# :Trag -l -i=w =trag#CWord()' for kind in keys(g:trag_kinds) call TragInstallKindMap(leader, kind) endfor endf function! TragInstallKindMap(leader, kind) "{{{3 " TLogVAR a:leader, a:kind if len(a:kind) == 1 let kind = a:kind let excl = index(g:trag_kinds_ignored_comments, kind) == -1 ? '' : '-x=i' exec 'nnoremap' a:leader . a:kind ':Trag -l -i='. kind excl '=trag#CWord()' exec 'vnoremap' a:leader . a:kind 'y:Trag -l -i='. kind excl '"' endif endf if !empty(g:trag_map_leader) call TragInstallMap(g:trag_map_leader) endif let &cpo = s:save_cpo unlet s:save_cpo autoload/trag/general.vim [[[1 13 " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Website: http://www.vim.org/account/profile.php?user_id=4037 " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Last Change: 2009-02-25. " @Revision: 7 function! trag#general#Rename(world, selected, rx, subst) "{{{3 let cmd = 's/\C\<'. escape(tlib#rx#Escape(a:rx), '/') .'\>/'. escape(tlib#rx#EscapeReplace(a:subst), '/') .'/ge' " let cmd = 's/\C'. escape(a:rx, '/') .'/'. escape(tlib#rx#EscapeReplace(a:subst), '/') .'/ge' return trag#RunCmdOnSelected(a:world, a:selected, cmd) endf autoload/trag/viki.vim [[[1 12 " @Author: Thomas Link (mailto:micathom AT gmail com?subject=[vim]) " @Website: http://www.vim.org/account/profile.php?user_id=4037 " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Last Change: 2009-02-27. " @Revision: 6 function! trag#viki#Rename(world, selected, from, to) "{{{3 let suffix = tlib#var#Get('vikiNameSuffix', 'bg', '') return trag#rename#Rename(a:world, a:selected, a:from, a:to, suffix) endf autoload/trag/rename.vim [[[1 34 " @Author: Thomas Link (mailto:micathom AT gmail com?subject=[vim]) " @Website: http://www.vim.org/account/profile.php?user_id=4037 " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Last Change: 2009-02-27. " @Revision: 4 function! trag#rename#Rename(world, selected, from, to, suffix) "{{{3 let rv = trag#general#Rename(a:world, a:selected, a:from, a:to) let from_file = a:from . a:suffix let to_file = a:to . a:suffix let bnr = bufnr(from_file) " TLogVAR from_file, to_file, bnr if filereadable(to_file) echom 'TRag: Cannot rename file, file already exists: '. to_file elseif filereadable(from_file) call rename(from_file, to_file) echom 'TRag: Renamed file '. from_file .' -> '. to_file endif if bnr != -1 if bufnr(to_file) != -1 call tlib#notify#Echo('TRag: Cannot rename buffer, buffer already exists: '. to_file, 'Error') else exec 'buffer '. bnr exec 'file! '. fnameescape(to_file) w! echom 'TRag: Renamed buffer '. from_file .' -> '. to_file if filereadable(from_file) && !filereadable(to_file) call tlib#notify#Echo('TRag: Inconsistent state. Please rename the file '. from_file .' -> '. to_file, 'Error') endif endif endif return rv endf autoload/trag/ft/viki.vim [[[1 18 " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Revision: 9 if !exists('g:loaded_trag') || exists('g:ftplugin_trag_viki') finish endif let g:ftplugin_trag_viki = 1 TRagDefFiletype viki txt TXT viki dpl TRagDefKind i viki /\C^\s*%%.\{-}%s/ TRagDefKind d viki /\C^\s*#\u\w*\s\+.\{-}\%%(id=%s\|%s=\)/ TRagDefKind h viki /\C^\*\+\s\+%s/ TRagDefKind l viki /\C^\s\+%s\s\+::/ TRagDefKind r viki /\C^\s\+\%%(.\{-}\s::\|[-+*#]\|[@?].\)\s\+%s/ TRagDefKind todo viki /\C\%%(TODO:\?\|FIXME:\?\|+++\|!!!\|###\|???\)\s\+%s/ TRagDefKind tag viki /\C\%%({\%%(idx\|label\):\s*%s\s*}\|#%s\>\|\[\[%s\]\]\)/ autoload/trag/ft/vim.vim [[[1 19 " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Revision: 6 if !exists('g:loaded_trag') || exists('g:ftplugin_trag_vim') finish endif let g:ftplugin_trag_vim = 1 TRagDefFiletype vim vim .vimrc _vimrc TRagKeyword vim [:alnum:]_:# TRagDefKind W vim /\C[^|]\{-}%s[^|]\{-}/ TRagDefKind d vim /\C\<\%(fu\%%[nction]!\?\s\+\|com\%%[mand]!\?\s\+\%(-\S\+\s\+\)*\)%s/ TRagDefKind f vim /\C\%(\\|setMethod\s*("%s"\)/ TRagDefKind c r /\C\%(\<%s\s*<-\s*set\%(Ref\)\?Class\>\|\s*<-\s*set\%(Ref\)\?Class\s*(\s*"%s"\)/ TRagDefKind l r /\C\%(^\s*%s\s*<<\?-\s*\|\<%s\s*=[^=]\)/ TRagDefKind r r /\C\s*<<\?-\s*%s/ TRagDefKind f r /\C\<%s\s*(/ autoload/trag/ft/json.vim [[[1 15 " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Revision: 6 if !exists('g:loaded_trag') || exists('g:ftplugin_trag_json') finish endif let g:ftplugin_trag_json = 1 TRagDefFiletype json json TRagDefKind d json /\C^\s\+"%s"\s*:/ TRagDefKind l json /\C^\s\+"%s"\s*:/ TRagDefKind r json /\C^\s\+".\{-}"\s*:.\{-}%s/ autoload/trag/ft/javascript.vim [[[1 17 " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Revision: 6 if !exists('g:loaded_trag') || exists('g:ftplugin_trag_javascript') finish endif let g:ftplugin_trag_javascript = 1 TRagDefFiletype javascript js TRagDefKind i javascript /\C^\s*\%(\/\/\|\/\*\).\{-}%s/ TRagDefKind d javascript /\C\%(\<%s\s*[:=]\s*function\>\|\\)/ TRagDefKind l javascript /\C\<%s\s*=[^=<>]/ TRagDefKind r javascript /\C[^=!<>]=\s*%s/ TRagDefKind f javascript /\C\(\/ TRagDefKind W ruby /\C[^;()]\{-}%s[^;()]\{-}/ TRagDefKind c ruby /\C\/ TRagDefKind d ruby /\C\<\%(def\s\+\%(\u\w*\.\)*\|attr\%(_\w\+\)\?\s\+\%(:\w\+,\s\+\)*:\)%s/ TRagDefKind f ruby /\<%s\>/ TRagDefKind i ruby /\C^\s*#%s/ TRagDefKind m ruby /\C\]/ TRagDefKind x ruby /\C\s\*class\>.\{-}<\s*%s/ autoload/trag/ft/markdown.vim [[[1 15 " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Revision: 20 if !exists('g:loaded_trag') || exists('g:ftplugin_trag_markdown') finish endif let g:ftplugin_trag_markdown = 1 TRagDefFiletype markdown md mdown mkd mkdn markdown mdwn TRagDefKind i markdown /\C^\s*