Vim Tips Wiki
Advertisement

Vimper is a set of gVim plugins to enable creation of development projects. Currently it supports definition of C/C++ projects (projects can also be created for developing vim plugins, mainly for demo purpose).

Introduction

Vimper was developed to provide an IDE like environment within gVim. Vim has lots of plugins which can be used to transform the editor into a complete development environment, the goal of Vimper is to collect the most useful of these plugins into one single package as well as add new functionality to create a comprehensive Development/Project Management environment.

Vimper source code is available on Google Code for anyone and everyone to play around with. Since it's in the early stages of development would really appreciate if people provide feedback. Please provide your feedback or log issues here.


Download & Install

Download

Vimper can be downloaded from Google Code Project or vim.org. Please not that the release in the Google Code Project is likely to be more up to date. You can also checkout the code from here.

Installation

To install Vimper simply extract the package contents into your local Vim runtime folder. On Unix platforms this should be ~/.vim, on Windows this should be $HOME/vimfiles.

Set the environment variable {VIMPER_HOME} to point to the directory to which the content was copied (eg. VIMPER_HOME=~/.vim).

NOTE: Vimper has not been tested on the Windows platform and would require Cygwin to work.

Pre-Requisites

For Vimper to work correctly the following should be available.

  • Unix
    • Perl - perl should be installed and available in your path.
    • Ctags - Exuberant Ctags is used, make sure that it's available in your path and being picked up rather than the standard ctags.

Packaged Plugins

Using Vimper

Current features include:

  • Tree based file explorer (VTreeExplore)
  • Auto generation of make files.
  • Integration and navigation of make errors/warnings.
  • Project Window (listing all defined projects)
  • Browser to View/Navigate Class/Structure/Function definitions
  • Search files within project and navigate to search results.

Brief

Vimper is an IDE like environment and hence the entry point is a project definition. To get started with Vimper you need to define/create projects. To create your first project do the following:

  • :VTreeExplore {Directory/Project Root}
  • In the explorer navigate to the project root and type 'A'.
    • This will guide you through a set of options for defining the project. More detailed information about the project options are provided below.
  • Once the project has been defined, or to open already defined projects use :Vimper command. This will open a list of all defined projects. To open the project click on it in this list.

Projects

Vimper currently supports C/C++ project definitions only.

Defining Projects

To define a project use :VTreeExplore {dir} to navigate to the desired folder and then press 'A' with your cursor on the folder which will be the project root directory. (Options available in the VTreeExplore window is detailed further in the VTreeExplore section of the doc.)

Project Options

  • Project Root Directory : The user is prompted to enter a project root directory. By default this is the directory selected in the explorer.
  • Project Type : Currently supported Project Types are C/C++ (cpp) and Vim Plugins (vim). This field is mandatory and does not have a default.

Once projects are defined, their definitions are added to a meta-data file which is read by vimper on startup to display a table of defined projects for the current user. Using the cursor keys navigate to the desired project and press <enter> or "o" to open the selected project.

C/C++ Projects

C/C++ projects are defined and maintained using Make. Creating a project of type cpp requires the definition of a few extra parameters which are used by these Makefiles.

The structure of a cpp project is as follows:

[PROJECT_ROOT]
     ||- project.mk
     ||- Makefile
     ||- [FOLDER]
       ||- subdir.mk
     ...

Along with the files mentioned above a common file {macros.mk} is also included. This file is located in the {$VIMPER_HOME/make/cpp} directory.

  • Project Output Directory : This is the directory where the build/make output will be put. By default this directory is set to <project root>/build.
  • Platform Architecture : Define the target build platform. amd64, etc.? If left empty the script will try to guess the platform based on the environment setting. If not found will default to x86.
  • Build Target : Define whether the output of the build is a library or executable. { Options : lib|library, exe}

All directories under the project root will be scanned for C/C++ files. If such files exist in any of the sub-directories the sub-directory will be included in the build. (Note: If a directory only contains header files it will not be included.)

Directories can also be added to the project at a later time by pressing "a" in the project explorer. This will create a new directory if required, if directory by the specified name already exists it will force add the directory to the build.

Build

Make and make output has also been integrated so that build can be executed and errors analyzed from within Vim. To start a build execute the command :VmkMake. This will launch make in the shell and once completed display the build results in a preview window. The errors and warnings generated by make can be navigated to using keys in the preview window or through commands. Selecting an error/warning will open the corresponding file/line. Functionality is equivalent to that of :cfile.

  • Navigating Errors/Warnings in Make:
Command Key Description
<enter> Open the error/warning under the cursor.
:VmkNext n Open Next error.
:VmkPrev p Open Previous error.
w Open Next warning.
v Open Previous warning.
:VmkQuit q Close the error buffer.
:VmkReop Reopen the build error window if it has been closed.
Class Browser

The class browser opens a window which shows the Class outline, such as Class Members, Class Methods, etc. For CPP files the entire class is constructed using the definitions in the header files. For C files only structures and methods are listed.

The Class Browser is activated for all C/C++ projects. This functionality relies on exuberant ctags and will not display the class/struct structure is ctags is not available.

NOTE: To ensure that ctags is work correctly use the :VProjTags command. This will generate the tags file for the entire project. This tags file will be used by the vim ctags and Omni Completion. The update of this tags file is not automatic and the use needs to execute the :VProjTags command whenever sources are updated.

  • Navigation: Use the following keys while in the ClassBrowser window to open the selected member.
    • 'o'/DoubleClick - Navigate to the member definition (in case of functions/methods go to the prototype definition)

Project Search

Search provides the ability to execute a regular expression search on all the supported filetypes within a project. e.g. in C++ projects the search is executed only on the c/c++/h files. It also opens up a window containing the search results and provides the ability to navigate to the results.

To search use the command *:VSearch which will then ask for the regular expression to search for and then execute the search and open the results window.

NOTE: VSearch requires perl to be installed and available in the path.

  • Navigating the results window:
Command Key Description
<enter> Open the error/warning under the cursor.
:VSNext n Next search result.
:VSPrev p Previous search result.
:VSQuit q Close the results window.
:VSReop Reopen the last search result window.

VTreeExplore

This plugin was originally created by T. Scott Urban. The plugin creates a tree based file explorer in vim. VTreeExplorer is used as the base in the navigation panel providing a view to explore files and directories.

Features have been added to the base explorer to provide functionality such as project definition, build, etc.

NOTE: For a detailed description of the core VTreeExplorer functionality refer to the VTreeExplorer help document shipped with this plguin.

(Some of the key mappings have been changed from the original VTreeExplorer setting. Please refer below for an updated version of the key mappings.)

  • VTreeExplore KeyMaps
*Key* *Description*
<enter>/'o' If the cursor is on a line with a file, open that file in another window. The last window visited is where the file will be opened, unless the previous window contains an unmodified buffer or there is only one window, in which case a new window will be opened for the file. If the cursor is on a line with a directory, load the directory if it isn't loaded, or toggle the fold for that directory, if the directory is loaded.
'O' Same as 'o' but use use the explorer window when opening the file (closing the explorer).
't' Same as 'o' but use new tab instead window when opening the file.
'X' Recursively expand the directory under the cursor.
'E' file-explorer| under the cursor.
'C' Change the directory under the cursor (or the parent directory, in case the cursor is on a file) to the root directory.
'H' Change the root directory to your home directory, defined by the environment variable $HOME.
'u' Change the root directory up one level, to the parent directory of the current root directory.
'p' Move the cursor to the parent directory of the directory under the cursor. Hitting 'p' multiple times will quickly take you to the top of the tree.
'r' Refresh the current directory. This command might unload sub-directories of the cursor dir, depending on current expansion.
'R' Refresh the root directory.This command might unload sub-directories of the cursor dir, depending on current expansion.
'S' Start a shell in the current directory.
'D' Switch between the three directory sorting modes, described at treeExplDirSort. Initial value can be set with global variable treeExplDirSort.
'.' Toggle showing hidden files. Initial value can be set with global variable treeExplHidden. Hidden files are those starting with a dot or those defined by the regular expression in the variable treeExplHidePattern.
'?' Toggle long help display at top of window.
'-' Delete the file or directory under the cursor. User will be prompted to confirm the delete. In case of a directory the delete is recursive.
'A' Create a new project. Details of creating projects are explained in the Projects section above.
'a' Add a directory to the current project. If directory doesn't exist it will be created.
'm' Build the current project. See the build section of the current project type for further details.

Useful KeyMaps

Key Command
F8 Vimper
C-f VSearch
C-S-b VmkMake
C-S-t VProjTags

NOTE: Instead of putting these mappings in the .vimrc file, they should be added to the {PROJECT_ROOT}/.vimproj file. This file is auto-generated every time a new project is created.

nmap <F8> :Vimper<cr>
nmap <C-f> :VSearch<cr>
nmap <C-S-b> :VmkMake<cr>
nmap <C-S-t> :VProjTags<cr> 
Advertisement