sponsor Vim development Vim logo Vim Book Ad

Source Explorer (SrcExpl) : A Source code Explorer for viewing definition(s) and contextual info

 script karma  Rating 1411/392, Downloaded by 29699  Comments, bugs, improvements  Vim wiki

created by
Wenlong Che
script type

The latest dev version of Source Explorer and screenshots can be downloaded from GitHub Homepage:



SrcExpl (Source Explorer) is a source code explorer that provides context for the currently selected keyword by displaying the function or type definition
or declaration in a separate window. This plugin aims to recreate the context window available in the IDE.

For example, you put the cursor on a function name in the Normal mode, its definition will show on the Source Explorer window a moment later. As soon as you do the 'double-click' operation using your mouse onto the Source Explorer window which had appeared on the bottom of (G)Vim, the definition and its context will be shown on the editor window. In srcexpl v1.2 and above, the function key which users mapped will play a important role that you can not only use mouse but also use keyboard in order to exploring source code in both GUI and cterm VIM.

The Source Explorer can work with 'Taglist' and 'NERD tree' very well. Both of them make (G)Vim looks like the IDE in Unix/Windows/Mac enviroment.


1\ Go insight the definitions of functions and various types of C/C++/Java language project, including function, marcos, structure, array, method, class, global variable, local variable etc.
2\ Double click using left mouse and your own map key (such as: <ENTER>) onto the  Source Explorer window can go forward to the preview context.
3\ Popup menu and Your own map key to go back from the preview context.
4\ Auto create and update the 'tags' file intelligently.


1\ Ensure that there is only one 'tags' file in your project PATH, or it would make VIM load all of them on the same time. For example: There are two tags file in the 'your_project' directory, so we will delete the excess 'tags' file in the 'sub_directory'.

... ...

[chewenlong@localhost ~]$ cd your_project/
[chewenlong@localhost your_project]$ pwd
[chewenlong@localhost your_project]$ ls
bar.c  sub_directory  tags
[chewenlong@localhost your_project]$ cd sub_directory/
[chewenlong@localhost sub_directory]$ ls
foo.c  tags
[chewenlong@localhost sub_directory]$ rm -rf tags
[chewenlong@localhost sub_directory]$ ls
[chewenlong@localhost sub_directory]$ cd ..
[chewenlong@localhost your_project]$ ls
bar.c  sub_directory  tags
[chewenlong@localhost your_project]$ vim bar.c

... ...

2\ Make sure the files you are exploring is unix-format, that is, there is no '\r'(displayed as '^M') at the end of each line. Because the plugin would make a jump mistake when executing EX-commands.

3\ If you want your VIM works like the IDE, just try a VIM plugin named 'Trinity (trinity.vim)':


This simple plugin can manage 'Source Explorer', 'Taglist' and 'NERD Tree' work together very well.

If you want to use VIM with Source Explorer in the UNIXs-console, I suggest map the keys below to jump from one window to another.

nmap <C-H> <C-W>h
nmap <C-J> <C-W>j
nmap <C-K> <C-W>k
nmap <C-L> <C-W>l

Below key mappings can replace the Vim feature for jumping to previously visited locations via jump list.

nmap <C-I> <C-W>j:call g:SrcExpl_Jump()<CR>
nmap <C-O> :call g:SrcExpl_GoBack()<CR>

The typical actions using srcexpl.vim are:

a\ Move the cursor onto a symbol word.
b\ As soon as the definition of the word is displayed on the preview window, we type <Ctrl-j> to jump into the previw window.
c\ Type the SrcExpl_jumpKey(<ENTER> as default) to jump to the exact context of its definition.
d\ Type the SrcExpl_gobackKey(<SPACE> as default) to go back to the previous position of the symbol word.
install details
1\ Unzip the archive into your ~/.vim directory. That should put srcexpl.vim in ~/.vim/plugin and srcexpl.txt in ~/.vim/doc.

2\ Add the followings in your .vimrc or _vimrc and change them by yourself

" // The switch of the Source Explorer                                         "
" nmap <F8> :SrcExplToggle<CR>
"                                                                              "
" // Set the height of Source Explorer window                                  "
" let g:SrcExpl_winHeight = 8
"                                                                              "
" // Set 100 ms for refreshing the Source Explorer                             "
" let g:SrcExpl_refreshTime = 100
"                                                                              "
" // Set "Enter" key to jump into the exact definition context                 "
" let g:SrcExpl_jumpKey = "<ENTER>"
"                                                                              "
" // Set "Space" key for back from the definition context                      "
" let g:SrcExpl_gobackKey = "<SPACE>"
"                                                                              "
" // In order to avoid conflicts, the Source Explorer should know what plugins "
" // except itself are using buffers. And you need add their buffer names into "
" // below listaccording to the command ":buffers!"                            "
" let g:SrcExpl_pluginList = [
"         \ "__Tag_List__",
"         \ "_NERD_tree_",
"         \ "Source_Explorer"
"     \ ]
"                                                                              "
" // The color schemes used by Source Explorer. There are five color schemes           "
" // supported for now - Red, Cyan, Green, Yellow and Magenta. Source Explorer         "
" // will pick up one of them randomly when initialization.                            "
" let g:SrcExpl_colorSchemeList = [
"         \ "Red",
"         \ "Cyan",
"         \ "Green",
"         \ "Yellow",
"         \ "Magenta"
"     \ ]
"                                                                              "
" // Enable/Disable the local definition searching, and note that this is not  "
" // guaranteed to work, the Source Explorer doesn't check the syntax for now. "
" // It only searches for a match with the keyword according to command 'gd'   "
" let g:SrcExpl_searchLocalDef = 1
"                                                                              "
" // Workaround for Vim bug @https://goo.gl/TLPK4K as any plugins using autocmd for    "
" // BufReadPre might have conflicts with Source Explorer. e.g. YCM, Syntastic etc.    "
" let g:SrcExpl_nestedAutoCmd = 1
"                                                                              "
" // Do not let the Source Explorer update the tags file when opening          "
" let g:SrcExpl_isUpdateTags = 0
"                                                                              "
" // Use 'Exuberant Ctags' with '--sort=foldcase -R .' or '-L cscope.files' to "
" //  create/update a tags file                                                "
" let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ."
"                                                                              "
" // Set "<F12>" key for updating the tags file artificially                   "
" let g:SrcExpl_updateTagsKey = "<F12>"
"                                                                              "
" // Set "<F3>" key for displaying the previous definition in the jump list    "
let g:SrcExpl_prevDefKey = "<F3>"
"                                                                              "
" // Set "<F4>" key for displaying the next definition in the jump list        "
let g:SrcExpl_nextDefKey = "<F4>"

3\ Enjoy vimming :-)

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
SrcExpl-6.0.zip 6.0 2018-06-19 7.0 Wenlong Che - Add color scheme feature - The user is able to easily identify the specific
  window by the color used for highlight when there are multi-windows open
  at the same time.
- Add a workaround for Vim bug @https://goo.gl/TLPK4K as any plugins using
  autocmd for BufReadPre might have conflicts with Source Explorer. e.g. YCM,
  Syntastic etc. - https://github.com/wesleyche/SrcExpl/issues/6
- Bug fix - https://github.com/wesleyche/SrcExpl/issues/4
SrcExpl-5.3.zip 5.3 2013-09-15 7.0 Wenlong Che - Fix a bug when operating the Quickfix window after closing the Source Explorer window.
- Handle the case when the cursor is located at the Quickfix window as same as other external plugins.
- Update doc/srcexpl.txt
SrcExpl-5.2.zip 5.2 2013-03-25 7.0 Wenlong Che - Add the fast way for displaying the previous or next definition in the jump list. The new feature is similar with the commands called cprev and cnext for operating the Quickfix list. You can add below config lines in your .vimrc or just update your Trinity to v2.1.
    1. " // Set "<F3>" key for displaying the previous definition in the jump list
       let g:SrcExpl_prevDefKey = "<F3>"
    2. " // Set "<F4>" key for displaying the next definition in the jump list
       let g:SrcExpl_nextDefKey = "<F4>"
- Fix a bug when clicking the default prompt line in the Source Explorer window.
SrcExpl-5.1.zip 5.1 2012-09-20 7.0 Wenlong Che 5.0
Replaced use of preview window with a named buffer.
Moved to github.
Added documentation.

Added two APIs for serving other plugins:
SrcExpl_GetWin(), getting the Source Explorer window number for those plugins based on multiple windows.
SrcExpl_GetVer(), getting the Source Explorer version for the forward compatibility.
Added debug/logging functions for the internal development.
srcexpl.vim 4.5 2012-08-01 7.0 Wenlong Che The Source Explorer can support Vim Highlight Searching in this version. Because srcexpl.vim can restore the user's setting named hlsearch after executing the EX command and redraw the screen.
srcexpl.vim 4.4 2012-07-31 7.0 Wenlong Che Change the variable named s:SrcExpl_markList to be a global one. So we can recover the context of mark list and continue to use SrcExpl_GoBack function although the plugin had been re-opened.
srcexpl.vim 4.3 2010-10-06 7.0 Wenlong Che Fixed a bug when the working 'tags' file was created with the commands 'ctags -L cscope.files'. In this case, the plugin could not change the relative path to the absolute one. Thank Trevor Brown for reporting this bug.
srcexpl.vim 4.2 2009-03-16 7.0 Wenlong Che Bug fixed: In Linux or other *UNIX OS, Source Explorer v4.1 would change the 'current work directory' to '~/' when updating the tags file. Thanks to Ozan Sener for the bug-report.
srcexpl.vim 4.1 2009-03-12 7.0 Wenlong Che Fixed a bug in Version 4.0 which would make you jump into a empty file when listing multi-tags information.
srcexpl.vim 4.0 2009-03-09 7.0 Wenlong Che In this version, the taglist() interface do the binary searching in the exact tags file instead of a linear search, so each tagging responses much more quickly than before even though the tags file of the source code project is so large. All we have to do is add an option in your ctags ultility (--sort=foldcase).
srcexpl.vim 3.9 2009-03-04 7.0 Wenlong Che New features: --- The 1st anniversary
1\ Manually updating or creating the 'tags' file using a new custom key named g:SrceExpl_updateTagsKey when you browse the source code without closing the Source Explorer window.
2\ Dynamically loading the tags database from one source code project to another without closing the Source Explorer window.
srcexpl.vim 3.8 2009-03-02 7.0 Wenlong Che I've implemented a local mark-stack mechanism using variable type of dictionary in this version, so you can trace into the source code more deeply without warring about the limit of 'A-Z' level using Vim's mark before.
srcexpl.vim 3.7 2009-02-27 7.0 Wenlong Che In this version, We do not try to tag something when we got the invalid symbol (only 0-9, a-z, A-Z, and '_' are valid) under the current cursor. So we should not feel unfrequently when we explore the huge source code project using "HJKL" to jump from a word to another.
srcexpl.vim 3.6 2008-12-28 7.0 Wenlong Che Let all the folds opened in order to avoid opening and closeing each fold every time.
srcexpl.vim 3.5 2008-11-08 7.0 Wenlong Che 1\ Add one new feature: Update different 'tags' file dynamically on different project PATH when opening the Source Explorer each time.
2\ Add one user interface variable named g:SrcExpl_updateTagsCmd, which can be set to execute particular 'ctags' utility program, "ctags -R *" as default.
srcexpl.vim 3.4 2008-11-03 7.0 Wenlong Che Bug fixed: Make "Source_Explorer" not display on the buffers list and menu.
srcexpl.vim 3.3 2008-09-16 7.0 Wenlong Che Bug fixed: The string of EX command is set to be case sensitive, so it is more accurate when excuting the EX command.
srcexpl.vim 3.2 2008-08-28 7.0 Wenlong Che 1\ Added one user interface variable named g:SrcExpl_jumpKey, which can be mapped to jump into the exact definition context, "<ENTER>" as default.
2\ Delete one user interface variable named g:SrcExpl_refreshKey, because it is almost not be used actually according to feedbacks from users.
3\ Added the protect mechanism when running multiple tab pages.
4\ Avoid additional refresh operation when the cursor had jumped into the definition context.
5\ Fixed a bug that setting a error mark on the [Jump List] line without judgement.

srcexpl.vim 3.1 2008-08-18 7.0 Wenlong Che Two bugs fixed:
1\ Avoid highlight the whole EX command when previewing the definition.
2\ Not update the Popup menu when the current word under the cursor
   had been tagged already, or it would be changed on the UNIXs platform.
srcexpl.vim 3.0 2008-08-07 7.0 Wenlong Che New feature: Local definition searching and preview using the interface of 'gd' command in VIM. Note that this is not guaranteed to work, the Source Explorer does not check the syntax for now, it only searches for a match with the keyword according to the command 'gd' when you enable the new variable named g:SrcExpl_searchLocalDef.
Improvement: Reimplement the jump mechannism when going back from the preview context using the mark stack with 'A-Z' (26 depth actually). It is more accurate than using the 'Ctrl-o' command.
srcexpl.vim 2.6 2008-07-26 7.0 Wenlong Che Update the mechanism and process when the Source Explorer work with other plugins, such as Taglist, NERD tree, etc. Of course, you must tell the Source Explorer what plugins are using the split windows according to a new MMI setting: g:SrcExpl_pluginList
srcexpl.vim 2.5 2008-07-15 7.0 Wenlong Che   In this version, I add a prompt line which contain the tag name and its counts when we do the multi-definition searching. A bug about folding in VIM is fixed. In srcexpl.vim, I desrcibed that how the Source Explorer works with the Taglist and the MiniBufExplorer on my platform.
srcexpl.vim 2.4 2008-07-08 7.0 Wenlong Che     In version 2.4, the srcexpl plugin should work more stable and more efficient than before.
    Firstly, I implemented the method of getting tags list without traversaling the 'tags' file. So parsing and showing the tags of whole project is more quickly, espacially in a large project. (e.g. The size of tags file in "Linux-2.4.0" is 19 MBytes which including more than 248000 lines data.)
    Secondly, it is more accurate to find the symbol definition because of the regular expression.
    Finally, I handled a potential problem of deleting buffers, and it may become a bug when changing the tags list in WIN32 platform.

srcexpl.vim 2.3 2008-04-05 7.0 Wenlong Che Bugfixed: When the current file which you are editing is not saved, the Source Explorer would not jump to the definition of the symbol under the cursor. This mechanism can handle the 'one-file-multi-buffers' situation very well.
srcexpl.vim 2.2 2008-03-26 7.0 Wenlong Che In this version(V2.2), I added a feature, which supported 'tags' file auto-updateing when you open the Source Explorer every time. And if the tags file  were not found, the Source Explorer would create one in the current directory according your choice. Besides, I fixed a bug of tags file loading on the mac OS X running enviorment. Thank Larry and Maqi for their freebacks and suggestions. :-)
srcexpl.vim 2.1 2008-03-23 7.0 Wenlong Che In this version, I implemented the method to do the recursion for searching the 'tags' file from the current directory to the root directory. In addition, the mechanism for vim version inspection is added. Finally, I rewrote the function named g:SrcExpl_OtherPluginAdapter() in order to adapt the privious postion of the editor window when using the Taglist and MiniBufExpl Plugins.
srcexpl.vim 2.0 2008-03-14 7.0 Wenlong Che Added an important feature, that is, multi-definitions list and explore.
When the symbol under the cursor is defined in several places, the Source Explorer window will list them one by one. You can select one of them by a double-click or a <Enter> key onto the exact line, and then we jump to the place that match the definition.
This feature is so important that you can only use one hand ( the one using the mouse :-) ) to explore the source code conveniently, and avoid the number selection when tagging a mulit-definition by <Left-Mouse> or <Ctrl-]>.
srcexpl.vim 1.2 2008-03-10 7.0 Wenlong Che Add one feature and two user interfaces.
You can use your own map key to force to complete one refreshing operation. And it will take a less waiting time sometimes.
Additionally, users can set update time interval by themselves in this version.
srcexpl.vim 1.1 2008-03-06 7.0 Wenlong Che Inthis version(v1.1), I added the following features
1\ add the 'SrcExplGoBack' item in popup menu when you click right button of your mouse. You will see that when you use srcexpl.vim for exploring the source code.
2\ add an interface for users who want to map their own key for do the 'SrcExplGoBack' function.
3\ 'SrcExplGoBack' is such a feature that it make user go back from 'definition contexts' in editor. When you click the 'SrcExplGoBack' item, it jump the privious place which your have explored just now.
srcexpl.vim 1.0 2008-03-04 7.0 Wenlong Che Initial upload
ip used for rating:

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