sponsor Vim development Vim logo Vim Book Ad

outline : Create your own custom view of the file based on regex

 script karma  Rating 0/2, Downloaded by 1354  Comments, bugs, improvements  Vim wiki

created by
Marc Weber
 
script type
utility
 
description
Vim has many possibilites to let you find the code you want to have a look at.
This script shows all matches of a regular expression in another buffer together with line numbers. The cursor will be placed where you have been.
So you won't loose orientation.

I think a small example will help you much to illustrate what this script can do for you

The script is called autoload/vl/ui/navigation/jump_to_code_by_regex.vim

and looks like :
==============================
[...]
function! vl#ui#navigation#jump_to_code_by_regex#Outline(regex, ...)
  exec vl#lib#brief#args#GetOptionalArg('try_higlight', string(0))
[...]
endfunction
[...]
function ...
==============================

After using the mapping you'll get
==============================
   17  function! vl#ui#navigation#jump_to_code_by_regex#Outline(regex, ...)
   66  function! vl#ui#navigation#jump_to_code_by_regex#JumpToPos()
   75  function! vl#ui#navigation#jump_to_code_by_regex#AddOutlineMappings(regex)
==============================
Pressing enter will take you to line 17 / 66 etc..

Of course you can also find definitions this way (use let as regex and you'll get)
====================
   19    let ft = &filetype
   20    let file = expand('%')
   21    let window = winnr()
[...]
=====================
Pressing <c-o> will take you back

I'v put some minor effort into higlighting the regular expression match. Thus you can use \zs and \ze to higlight special words.
How nice this works depends on the already existing syntax definitions. This can be improved much
 
install details
Use http://www.vim.org/scripts/script.php?script_id=2014 instead.

Just source the file and follow the instructions.
You'll be asked before any action is taken.

If you don't feel comfortable installing to .vim insntall to another arbitrary directory and add it to your runtimepath
(let runtimepath+= ..)

Default mappings are provided in the
function! vl#ui#navigation#jump_to_code_by_regex#AddOutlineMappings(regex)

ftplugin/vim.vim:
call vl#ui#navigation#jump_to_code_by_regex#AddOutlineMappings('^\s*fun.*')
../c.vim:
"outline mappings and regex
let s:cpp_prefix='\%(\w\+\s\+\)\='
let s:ret_type='[a-zA-Z0-9\&* \t]\+\s\+'
let s:name='\%(\w\+\::\)\=\w\+\s*'
let s:func_args='([ \t,0-9a-zA-Z\&*\n\[\]_]*)\ze\s*{'
let s:func_pattern=substitute(s:cpp_prefix.s:ret_type.s:name.s:func_args,'\\s','[ \\t\\n]','g')
let g:func_pattern=s:func_pattern
let s:pattern = string('\%('.s:func_pattern.'\)\\|class')
exec 'noremap <buffer> <m-o><m-s> :call vl#ui#navigation#jump_to_code_by_regex#Outline('.s:pattern.')<cr>/'
exec 'noremap <buffer> <m-o><m-l> :call vl#ui#navigation#jump_to_code_by_regex#Outline('.s:pattern.')<cr>'
etc..

If you still have problems drop me a mail.

Patches welcome.
 

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
vimlib_outline_installer_sourceme.zip 0.0 2007-07-08 7.0 Marc Weber Initial upload
ip used for rating: 142.132.191.50

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.
   
Vim at Github