We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free. Anti-spam check. Do not fill this in!==Example== Usually a language like Python would be used to generate a tags file, but Vim script can do the job, although more slowly. To illustrate the process, the following script reads specified files and generates a tags file that indexes every word in each file. <pre> " Read file and search each line for all occurrences of pattern. " Return list of search hits. " Each item in list is a list: [linenr, colnr, match] function! SearchFile(file, pattern) let results =  let lines = readfile(a:file) for linenr in range(len(lines)) let line = lines[linenr] let i = 1 while 1 let p1 = match(line, a:pattern, 0, i) if p1 < 0 break endif let p2 = matchend(line, a:pattern, 0, i) call add(results, [linenr+1, p1+1, strpart(line, p1, p2-p1)]) let i += 1 endwhile endfor return results endfunction " Search each file in filespec (e.g. '*.txt') for all occurrences of pattern. " Return list of lines suitable for a tags file. function! MakeTags(filespec, pattern) let tags =  for file in glob(a:filespec, 0, 1) for hit in SearchFile(file, a:pattern) call add(tags, printf("%s\t%s\t/\\%%%dl\\%%%dc/", hit, file, hit, hit)) endfor endfor return sort(tags) endfunction </pre> The above script can be used like this: <pre> new call setline(1, MakeTags('*.txt', '\<\h\w*')) </pre> All <code>*.txt</code> files in the current directory are searched, and each hit (matching text, file, line, column) creates an item in the resulting tags file. The example places the tags lines in a new buffer, which would generally be saved to a file called <code>tags</code> (no extension). Each line will be similar to the example shown earlier. The pattern <code>\<\h\w*</code> finds all words (actually program identifiers): <code>\<</code> is the beginning of a word; <code>\h</code> is <code>[A-Za-z_]</code>; <code>\w</code> is <code>[0-9A-Za-z_]</code>. The <code>while 1</code> loop exits when no match occurs (<code>p1 < 0</code>). Summary: Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA Cancel Editing help (opens in new window) Retrieved from "https://vim.fandom.com/wiki/Tags_that_jump_to_line_and_column"