Fly Vim
Fly Vim
vim
User’s Guide
Revision 1.0
1
Table of Contents
1 What is fly.vim? ...................................................................................................................4
2 What platforms? ..................................................................................................................4
3 What dependencies? ............................................................................................................4
4 How to install and use? ........................................................................................................4
5 Preview Please? ...................................................................................................................4
6 Features Quick Reference? ..................................................................................................5
7 A few steps before you start,................................................................................................9
7.1 Jump Start .....................................................................................................................9
7.2 Pre Build Databases ......................................................................................................9
8 After you start, ....................................................................................................................9
8.1 Navigation Tab Bar ..................................................................................................... 10
8.1.1 Results Tab .......................................................................................................... 10
8.1.2 Cache Tab ............................................................................................................ 12
8.1.3 Settings Tab ......................................................................................................... 12
8.1.3.1 Environment ................................................................................................. 12
8.1.3.2 Toggle .......................................................................................................... 13
8.1.3.3 Flush Persistent Cache .................................................................................. 13
8.1.4 Help Tab .............................................................................................................. 13
8.2 Editing Window[s] ...................................................................................................... 13
9 Commands Description ..................................................................................................... 14
9.1 Launch Command ....................................................................................................... 14
9.1.1 SW (Switch) ........................................................................................................ 14
9.2 Cscope Commands ...................................................................................................... 14
9.2.1 BD (Build Cscope Databases) .............................................................................. 14
9.2.2 LD (List Cscope Databases) ................................................................................. 14
9.3 List Commands ........................................................................................................... 15
9.3.1 LS (List directory) ............................................................................................... 15
9.3.2 LB (List Buffers) ................................................................................................. 16
9.4 Symbol Search in Source Code ................................................................................... 17
9.4.1 CS (Query Cscope) .............................................................................................. 17
9.4.2 GR (Grep) ............................................................................................................ 18
9.5 Build Commands ........................................................................................................ 19
9.5.1 MK (Make) .......................................................................................................... 19
9.6 Web Commands .......................................................................................................... 19
9.6.1 WS (Web Search) ................................................................................................ 20
9.6.2 OW (Open Web URL) ......................................................................................... 21
9.7 Stack Commands ........................................................................................................ 22
9.7.1 LF (Left) .............................................................................................................. 23
9.7.2 RT (Right) ........................................................................................................... 23
9.7.3 LK (List Stack) .................................................................................................... 23
9.8 UNIX Man Pages ........................................................................................................ 24
9.8.1 TM....................................................................................................................... 24
9.8.2 MAN <sym> ........................................................................................................ 25
2
9.8.3 MAN N <sym> .................................................................................................... 25
9.9 Sandbox Comparison Commands ................................................................................ 25
9.9.1 TCVS .................................................................................................................. 25
9.9.2 TSVN .................................................................................................................. 25
9.9.3 TIE ...................................................................................................................... 25
9.10 Restore Session ....................................................................................................... 26
9.10.1 RS <file> ............................................................................................................. 26
9.11 Tab Navigation Commands ..................................................................................... 26
9.12 Commands in ‘Settings’ Tab.................................................................................... 26
9.13 Misc ........................................................................................................................ 26
10 Known Issues .................................................................................................................... 26
11 Wish list ............................................................................................................................ 27
12 History and Future ............................................................................................................. 28
13 License .............................................................................................................................. 28
14 Disclaimer ......................................................................................................................... 28
3
1 What is fly.vim?
Are you using vim as your editor? If yes, fly.vim may be useful for you. fly.vim is a vim plugin
that may enhance your vim experience (and productivity) with an integrated code development
environment. The plugin facilitates rapid code-walkthrough (or flythrough as I call it), enables
instant symbol searches and cross references in a large code base, manages stacks of multiple
files and integrates code reviews and compilation, all within a simple and intuitive user interface.
fly.vim integrates seamlessly with source code index databases (Cscope for now), web search
engines (Google and Yahoo) and UNIX man pages. Most functions are mapped to shortcut keys,
allowing you to fly through a large code base or web in a convenient manner. Using the shortcut
mappings, you may search for symbols (or multi-word phrases) after visually highlighting them,
or by typing them on vim command line or by taking the cursor to the symbol in a vim window.
Although there are quite a few features to talk about later, it is very easy to get started,
2 What platforms?
The plugin has been in use on Linux and FreeBSD with vim 6.x and 7.y.
You are free to try it out on other platforms. Please make sure the dependencies are met. If you
get it to work on other platforms, please let the plugin developer[s] know. ([email protected])
3 What dependencies?
Dependencies are very few and in all likelihood your system probably has them already.
The plugin internally uses basic shell commands: find, xargs, grep, cut, mkdir, man that should
be available on all UNIX shells. The plugin also uses open source tools cscope and elinks. Please
make sure these are installed already.
5 Preview Please?
The following page shows a sample screenshot. More screenshots can be found later in this guide
where individual features are described. The plugin has a control window to access most features
4
and also a pre-defined set of mappings to run most commands. Results for most commands show
up on the plugin’s control window – referred to as fly control window hereafter. Display for the
fly control window could be toggled anytime.
For all commands, user may select any one of the results just by hitting an <Enter> key on the
result line in fly control window. The intent is to provide a unified UI for most features. Most
often a result line is associated with a tuple <filename, line number>. A hit on <Enter> key on
result line opens associated file for editing and takes you to that line number. For web searches
the result line corresponds to a URL and a hit on that line opens up the URL in a separate vim
window. The sample screenshot shows results for a Cscope symbol search command in the fly
control window and also shows that the file associated with selected result line is opened in an
edit window.
5
It is recommended to use vim mapping (when defined) for a feature. Almost all mappings use the
vim <Leader> character. Default vim <Leader> is ‘\’. You may define your own mappings if
there is a conflict with existing set of mappings in your vim environment or otherwise also as per
personal taste. The mappings are defined at the tail end of plugin source file, so that it’s easy to
locate and change them when you want to do so.
You may also redefine the <Leader> as per personal preference e.g.
:let mapleader = ","
6
absolute path.
LB <Leader>lb List all buffers currently open in vim
Grep Commands
GR [opt] <sym> Grep for <sym> in all the files currently listed in the
fly control window. The options are command line
options to UNIX grep. The command currently works
only for results of CS/LS/GR command.
Build Commands
MK <Leader>b Build/compile source. You must have done "cd" at
vim command line to the dir where builds are done.
Also, makeprg should have been set if applicable.
E.g. :set makeprg=gmake
Read File Command
RD <file> • Read <file> containing a list of files.
• Read <file> containing log of a build/compilation.
Web Commands
WS <Leader><Leader>w Web Search for symbol under cursor or visually
highlighted text. There are two choices for internet
search engines as of now – Google and Yahoo. A
choice for the search engine and number of search
results can be made in Settings Tab Toggle section.
7
stack)
LK List the contents of buffer stack in current edit
window in focus. (Currently) It is not supported for
Web and Man pages window.
Code Review/Sandbox Comparison Commands
TCVS Toggle command to “tie” or “untie” the current
sandbox (source base selected by choice of Cscope
database) to CVS. For every file that is opened in the
edit window using fly commands, CVS vimdiff is
shown as well in another window.
let g:sandbox=”/absolute/path/to/root_of_sandbox/”
8
<Leader>4 Go to Help Tab
Commands in Settings Tab
Toggle the case sensitivity of Cscope queries.
Toggle the choice of Internet Search Engine (Google
or Yahoo)
Toggle the choice of internet search results (10, 15,
20, 30, 40, 100)
I usually pre-build Cscope databases before starting vim, though this is not necessary. You may
build database from the plugin itself using BD command. All you have to do is,
• Change directory to the root of the source tree (or subtree) that you want to work with.
• Launch vim. Run the BD command.
And you are all set to go. Cscope database is built in background and kept in $CSCOPE_DIR if
it is set. Otherwise it is kept in the same directory as the root of the source.
You may chose to pre-build all your Cscope databases that you usually work with and keep them
in a reference directory. The environment variable CSCOPE_DIR must be set to this directory. The
file listing used to build should preferably have absolute path names for files although that is not
required for most commands. Cscope databases must be named with extensions ‘.out’ or ‘.db’.
For faster search it is recommended to build indexed databases using –q option in Cscope. The
steps are summarized as follows,
9
The fly control window shows up at the bottom of all other windows opened in vim. The control
window is a read-only vim window. Vim editing (write) commands in the control window are
not expected by the plugin, however other vim commands (including movements and searches)
should be okay.
Following screenshot shows the fly control window and default contents when CSCOPE_DIR is set
in the host shell environment.
Editing Window
Navigation Tabs
Fly Control
Window
The fly control window has a Navigation Tab Bar to select different choices offered by fly today.
The current Tab1 Selection is highlighted. Default Tab Selection is Results. Other Tabs could be
selected by taking the cursor to the Tab text followed by <Enter>. The plug-in also has default
mappings <Leader>1, <Leader>2, <Leader>3 and <Leader>4 to navigate through these Tabs.
This tab shows results of query commands. The top line in this Tab shows the command that was
executed. Lines following that show the result lines that may be selected by just hitting <Enter>.
1
The plugin was developed before the Tabs were introduced in vim and hence they may seem out of style here.
Well, some day the fly developer[s] may enhance it to the use vim tabs.
10
Figure 1 Result Tab
The set of screenshot above demonstrate selection of a Cscope database. The plugin run LD
command on the vim launch automatically. The LD command lists Cscope databases stored in
CSCOPE_DIR. The databases could be organized in a sub-tree underneath CSCOPE_DIR as
shown in this example. A flat file structure under CSCOPE_DIR is fine as well.
There is one Cscope database in this example that is kept in a sub-tree. The rest two are stored at
CSCOPE_DIR level. The sub-trees are listed in traditional explorer way and could be expanded
or collapsed just by <Enter>.
A Cscope database underneath a sub-tree could be selected by <Enter> and the selection would
show up on the top line in fly control window. This is the Cscope database that will be used for
subsequent Cscope queries. Cscope database selection could be changed at any point of time
though.
For most fly commands the behavior is same as described in the example above. The command
shows up on the topmost line in fly control window under Results tab and the results of the
command show up on subsequent lines. Any of the result line could be selected (or activated) by
<Enter> key.
11
8.1.2 Cache Tab
The cache tab displays the cache of the commands executed in the past. One may revisit the
results of a previously executed command by just hitting an <Enter> on the line. For example in
the following screenshot a search for a symbol ‘select’ was done in past on cscope database for
vim64 sources. The search results could be revisited by <Enter> on the line showing the cache
entry for file search ‘Select’.
Most recent command in the cache is highlighted with “>>”. The cache tab also has windows
explorer like interface to explore the cache entries.
For every Cscope database that was selected in past there is an explorer-sub-tree in the cache.
The cache is not supported for build commands and web commands for now. This cache is not
persistent and is lost across vim launches.
The Settings Tab shows current settings and environment for the plugin. It also allows one to
change some of the plugin settings.
8.1.3.1 Environment
12
For now, there is only one environment variable CSCOPE_DIR that it shows in the environment
section. It also shows currently selected Cscope database.
8.1.3.2 Toggle
In the toggle section, it allows one to toggle case-sensitivity of Cscope searches, toggle the
choice of the Internet search engine (Google or Yahoo for now), toggle the count for Internet
search results (10, 15,20, 30, 40, 100) and toggle the choice of split for fly windows (web/man).
In order to toggle the choices, all one has to do is to hit <Enter> on that line and cycle through
the choices.
It also allows one to flush the cache of man pages and web pages. This cache is persistent as
opposed to the command cache. In order to flush the cache, all one has to do is to hit <Enter> on
that line.
The editing window is a regular vim window. There could be several of those open based on a
user’s vim multi-window usage style. The plugin remembers current window of focus and a hit
13
on the result line for a query initiated from that window opens the file in the same window.
Buffer stacks are maintained on per window basis. Navigation (up and down) on a buffer stack
could be done for each editing window separately.
9 Commands Description
9.1 Launch Command
9.1.1 SW (Switch)
This command is used to launch/display or hide the Fly control window. The first call initializes
the plugin and shows the control window at the bottom. Subsequent calls just toggle the display
of the control window. Context of fly control window is preserved across the toggles. The
context includes settings, cache and results for each command executed so far.
This command builds cscope database for the source tree specified by g:root. If g:root is not
specified the cscope database is built for the source tree rooted at current directory.
The database is built in background and the command returns immediately. You may start using
Cscope search commands right away for smaller source trees as the build succeeds quickly. The
build may take longer for larger code bases and the plugin will notify you in case you run queries
before the database is ready.
The built database is kept in $CSCOPE_DIR if that is specified or else it is kept in the root
directory of the source tree.
This command shows all the pre-built Cscope databases in $CSCOPE_DIR. If there are multiple
Cscope databases for one or multiple sandboxes, they could be organized in a directory tree
structure. The results will show the listing in explorer trees that could be collapsed or expanded.
A Cscope database could be selected by <Enter> on any of the result lines. The selected Cscope
database shows up in the topmost line in result tab and the environment section in Settings tab.
An explorer tree for the selected Cscope database shows up on Cache Tab. Queries done on this
Cscope database could be revisited by exploring this tree in Cache. Cscope database could be
revisited by exploring this tree in Cache.
14
9.3 List Commands
The LS command lists the directory specified in argument as an explorer-tree. User may open
any of the files in result listing for editing just by <Enter> on the line listing the file.
15
In case there are no arguments specified to LS, the directory of the file currently open in the
window in focus is listed.
The LB command is basically the ls command in vim. However, the buffer listing is shown in fly
control window. A user can reopen the file just by hitting an <Enter> on the buffer listing.
16
9.4 Symbol Search in Source Code
There are two commands offered for search, for now, - Cscope search and Grep.
The CS commands perform traditional Cscope queries on currently selected Cscope database.
The arguments to CS are the same characters that users of cscope_maps.vim are already familiar
with (cscope.sourceforge.net).
There are two sets of mappings defined for CS. The first set with <Leader><Leader> for
performing queries on the symbol under cursor. The other set with <Leader> is for User to type
in the symbol at vim command line. There is no auto-completion support yet for typing in these
symbols. Only for file searches, partial name could be specified otherwise full symbol name is
expected for the command.
The very same sets of mappings work in visual mode too. First set <Leader><Leader> performs
queries on the visually selected text. The second set <Leader> takes user to the command prompt
but with visually selected text as argument and then user is free to change the text on command
line.
17
9.4.2 GR (Grep)
The GR command is traditional UNIX [e]grep that runs on the set of files currently listed in fly
control window (that may be as a result of another fly command e.g. LS, CS etc)
.
18
For GR, user may specify same options on vim command line for GR as he/she would for UNIX
grep command on shell prompt.
This command runs makeprg and shows results in the fly control window. And then user may
open the errors/warnings by in edit windows. A user may visually highlight a phrase in an error
message and perform an internet search on the selection. The error listings show up very slow if
the error messages run in a few hundreds.
These commands are useful when one comes across a URL in the file being browsed or edited
and wants to see the URL contents. These commands are also useful when you want to perform
web search (on Google and Yahoo e.g.) for a phrase present in current file e.g. errors/warnings of
compilation, usage of a library API etc.
Well, the URL contents are dumped in text format. And this is certainly not as effective as the
real browsers – the intent here is to quickly browse web in the middle of code flythrough. It is
useful to quickly cut and paste example code segments from web using vim commands or to
quickly find out what an error or warning message may mean. This is not meant to be your web
browser.
19
9.6.1 WS (Web Search)
This command performs web searches for text in search engines (Google or Yahoo).
There are two kinds of mappings defined for WS. First one with <Leader><Leader> for
performing web search for the symbol under cursor on currently selected Search Engine (Google
or Yahoo). The other kind with <Leader> is for User to type in the text at vim command line.
The very same mappings work in visual mode too. First kind with <Leader><Leader> performs
web search on the visually highlighted text. The second one <Leader> takes user to the
command prompt but with visually highlighted text as argument and then lets the user change the
text on command line.
Results of the search are displayed in the result tab in fly control window. User may jump to any
of the results by hitting the <Enter> key on that line – this results in contents being fetched from
URL associated with the result line and the contents being displayed on a separate vim window
(__FlyWeb) as shown in the next screenshot.
20
9.6.2 OW (Open Web URL)
This command fetches contents of the page referenced by the URL argument and shows the
contents in a separate vim window (__FlyWeb).
There are two kinds of mappings defined for OW too. First one with <Leader><Leader> for
opening the URL that is present somewhere in the current line. The other one with <Leader> is
for User to type in the URL on vim command line.
The very same mappings work in visual mode too. First one <Leader><Leader> opens the URL
selected visually. The second one <Leader> takes user to the command prompt but with visually
selected text as argument and then lets the user change text argument on vim command line.
21
9.7 Stack Commands
Concept of stack applies to editing windows (there may be multiple of those), web browsing
window, man pages window and fly control window. The plugin maintains a stack for all
windows currently open. User may navigate up and down on this stack in a window.
For edit windows the stack contains buffers/files that were opened in that window (e.g. user may
start with opening a file in a window, but may move on to other files from the results of fly
commands).
For the fly control window, the stack commands apply to the Results of previous fly commands.
The stack navigation takes one back and forth through the results of fly commands executed so
far.
22
For the web browsing window, the stack commands are equivalent to ‘Back’ and ‘Forward’
functions on a typical web browser.
For the man pages window, the stack commands helps one navigate through previously opened
man pages. These are useful when you open the man page for a symbol and then follow the
“SEE ALSO” section towards the end of a man page to see other man pages in the chain.
9.7.1 LF (Left)
The LF command moves down the stack in current window of focus. The mapping for this
command is <Leader>, (You may imagine using “<”– back/left key after <Leader>). Some users
map <Ctrl-t> to this command. (Those who are used to ctags)
9.7.2 RT (Right)
The RT command moves up the stack in current window of focus. The mapping for this
command is <Leader>. (You may imagine using “>”– forward/right key after <Leader>). Some
users map <Ctrl-h> to this command.
The LK command shows contents of stack in the current window of focus. This is useful when
you are working on a new code base and want to take notes of the function call chain – just yank
and paste the results of this command to your notes file.
23
9.8 UNIX Man Pages
The plugin allows users to open man pages in a vim window, thus allowing them to be able to
view man pages when needed in an adjacent window, copy and paste header file includes and
example code segments mentioned in the man pages.
Man page queries can be run from any window (including the man page window itself) and the
results show up in __FlyMan window.
The man page window also has its own stack and thus one may navigate back and forth between
previously opened man pages. The feature is useful when user wants to open man pages one after
another following the chain of “SEE ALSO” section in man pages.
9.8.1 TM
24
9.8.2 MAN <sym>
Open the default man page for the symbol (under cursor or typed).
Open the man page for symbol (under cursor or typed) in section specified in argument.
These commands are useful for comparing one sandbox to another sandbox or to the image in
source code control repository. For example, before committing changes in a sandbox to source
code repository, you may open list of modified files using RD command and then tie the sandbox
to CVS using TCVS. You may then navigate through each of the modified file by opening them
from the fly control window, the CVS diff is shown automatically in another window.
At least one file must have been opened in an edit window. Run these commands while you are
(or the cursor is) in that edit window.
9.9.1 TCVS
This command ties your sandbox that is chosen automatically on choosing a cscope database to
CVS. For every file that gets opened in the edit window using fly commands, CVS diff is shown
in another window.
TCVS is a toggle command. The same command can be used to untie the sandbox from CVS.
The vim plugin cvscommand.vim must have been installed in order for this command to work.
9.9.2 TSVN
This command ties your sandbox that is chosen automatically on choosing a cscope database to
SVN. For every file that gets opened in the edit window using fly commands, SVN diff is shown
in another window.
TSVN is a toggle command. The same command can be used to untie the sandbox from SVN.
The vim plugin svncommand.vim must have been installed in order for this command to work.
9.9.3 TIE
This command ties your sandbox that is chosen automatically on choosing a cscope database to
another sandbox that is specified using g:sandbox.
25
:let g:sandbox= “/absolute/path/to/root_of_sandbox/”
For every file that gets opened in the edit window using fly commands, vimdiff with
corresponding file in the other sandbox is shown automatically in another window.
TIE is a toggle command. The same command can be used to untie the sandbox from the other
one.
For now, it’s implemented only for results of CS command. User may save the contents of fly
control window (when results for a CS commands are displayed) in a file. That file could be
opened later with RS command. Contents are displayed back in fly control window and user may
jump to any of the result files.
9.13 Misc
There are a few other commands like you could open any of the result files in a separate window
other than the edit window from where fly command was run. The new window could be vertical
or horizontally split.
You could also grep the results of CS/LS/GR command by editing the first line in result window
to pipe it to UNIX grep command.
10 Known Issues
• Cscope database must be selected before using any of the CS commands or else behavior
is undefined. The check is not put in the plugin before running CS.
• If the list of errors or warnings from MK were a few hundred in number, the MK
command takes a couple of minutes to return.
• Error handling is not complete. The commands are expected to be used as documented or
else sometimes you may see unexpected behavior.
26
• Sometimes, the buffer stack is lost.
In case you could reproduce a bug consistently. Please use “redir” command to capture the errors
and report to the fly maintainers as follows.
11 Wish list
I jotted down a few in my wish list below in no particular order. If you have more in mind you
may add to the list and may be implement them into the plugin. Please send an email if you wish
to do so to [email protected].
• Multiple Cscope database selection. This would allow users to select multiple database
and subsequent cscope queries will be run on each one of selected cscope databases.
• Auto completion of arguments. Currently the arguments to fly command are not
automatically completed (if they were to be file names or code symbols present in
database).
• Man page search. Currently the man pages are opened up for exact symbol. This search
would allow user to search for man pages matching a symbol. (It would use man –k in
background.
• Integrate GNATS/Bugzilla.
27
12 History and Future
The plugin was developed out of need to filter and navigate through a large number of Cscope
search results back in vim 6.x days. Traditional Vim and Cscope integration was there but I
didn’t find it good enough to serve this need. Current state of this plugin has evolved to serve
many more needs than this original one. But then, some of those needs are now natively served
by vim 7.x+ also.
The best part of vim plugins is that most users are also developers. In larger user community the
plugin may find more developers for itself. The plugin design is flexible to add new features. If
there is enough user base and enough interest in contributing to development, I should probably
put design guidelines (Developer’s Guide) in public domain and may be put the plugin source in
one of the open source hosting repositories.
In case you have any feedback or are interested in contributing to the development do send an
email to [email protected].
13 License
The plugin fly.vim is released under VIM License that you will find at
http://vimdoc.sourceforge.net/htmldoc/uganda.html#license
14 Disclaimer
The plugin fly.vim comes with no warranty of any kind, either expressed or implied. In no event
will the copyright holder and maintainers of the plugin be liable for any damages resulting from
use of the plugin.
28