Vim: Pathogen Plugin

Pathogen is a simple Vim plugin written by Tim Pope that makes managing plugin files easy. Typically, plugin files are scattered all over the plugin, autoload and doc subdirectories of vimfiles. It becomes hard to distinguish which .vim files belongs to which plugin. This makes updating or uninstalling plugins quite hard.

Pathogen allows the user to place the files of each plugin in their own private subdirectory. To update or uninstall a plugin, just manage that plugin’s subdirectory. By default, the root directory that Pathogen looks for is named bundle. At runtime, Pathogen forms a list of all these plugin subdirectories and appends them all to runtimepath, which is the path that Vim looks through for loading plugins.

Installation

  1. Place pathogen.vim in vimfiles/autoload directory.
  2. Add this line to your vimrc:
    call pathogen#runtime_append_all_bundles()
    

Usage

  1. Create a bundle subdirectory inside the vimfiles subdirectory.
  2. Create a subdirectory inside bundle for each plugin you use. You can use the plugin name as the directory name.
    1. For plugins that ship with a plugin-autoload-doc directory structure, just unzip the plugin files inside this subdirectory.
    2. For plugins that ship as a single .vim file, create a further plugin or autoload subdirectory (as required) and place the plugin file in it.

Note: If you prefer that installation, updation and uninstallation of plugins be automated, check out the vim-addon-manager plugin.

Using vim-addon-manager on Windows

vim-addon-manager is a Vim plugin written by Marc Weber that can be used to automatically manage Vim plugins. Most popular plugins install many files into several directories, thus making the task of installing, updating and uninstalling them quite tedious. vim-addon-manager attempts to make these tasks easy and automatic. It is still a work-in-progress, especially so on Windows, on which I found it to be quite flaky.

Before Installation

vim-addon-manager automatically pulls off plugins from the Internet both for installation and for updating. So, it requires a set of tools to be installed on Windows before it can be used.

  1. Curl: vim-addon-manager uses Curl to download files from the web.
    • Install a Windows binary of Curl and remember to add the curl.exe directory to the PATH environment variable.
  2. 7-Zip: Many Vim plugins are packaged as .gz or .bz2 files. vim-addon-manager requires a tool to uncompress these files. I prefer to use the awesome 7-Zip tool for this purpose.
    • Install 7-Zip if you do not already have it. Add the 7z.exe directory to the PATH environment variable.
  3. Git: A lot of Vim plugins are hosted on GitHub and other public Git repositories. A Git installation is convenient since vim-addon-manager itself is hosted on GitHub. (If you do not want to install Git, zip files of vim-addon-manager are available from GitHub. See Marc Weber’s comment below.)
    1. Currently, there are 2 versions of Git for Windows available. I prefer to install the MsysGit version. During its installation, make sure to choose the option Run Git from the Windows Command Prompt.
    2. The MsysGit installer should have added the Git\cmd directory to the PATH environment variable. Add it to PATH if this is not the case.
  4. Hg or SVN: A few Vim plugins are hosted on Sourceforge, Bitbucket and other public repositories that use Mercurial or Subversion. If the plugin you use is hosted on such a service, install Hg or SVN binaries for Windows and add their directories to the PATH environment variable.

We are now ready to install vim-addon-manager! :-)

Installation

  1. vim-addon-manager will store its own files and the files of all the plugins it will handle in one directory. %USERPROFILE% on Windows is a good place to host such a directory. %USERPROFILE% on Windows 7 resolves to C:\Users\Joe. Create a directory named vim-addons in %USERPROFILE%.
  2. Open a command prompt in vim-addons and install vim-addon-manager here using:
    $ git clone git://github.com/MarcWeber/vim-addon-manager.git
    
  3. Open your vimrc and add these lines:
    "-------------------------------------------------------------------------------
    
    " Vim Addon Manager
    
    fun LoadVimAddonManager()
    
        " Load vim-addon-manager
        set runtimepath+=$USERPROFILE/vim-addons/vim-addon-manager
    
        " Install/load these plugins
        call scriptmanager#Activate( [ "vim_plugin_1", "vim_plugin_2" ] )
    endf
    
    " Activate the manager after Vim startup
    au VimEnter * call LoadVimAddonManager()
    
    "-------------------------------------------------------------------------------
    

The first time you run vim-addon-manager it will load another plugin named vim-addon-manager-known-repositories. This plugin is used as a database of all Vim plugin names and URLs to obtain them from. After this, vim-addon-manager will try to install the plugins listed in scriptmanager#Activate().

Usage

  • To install a new plugin, just add its name to the list in the call to scriptmanager#Activate(). It will installed the next time Vim is executed.
  • All the existing plugins listed in the call to scriptmanager#Activate() are loaded at runtime everytime a new Vim instance is invoked.
  • To update all the installed plugins from the web use the command :UpdateAddons
  • To uninstalla plugin:
    1. Open vimrc and remove the plugin name from the list in scriptmanager#Activate(). This means that it will not be loaded at runtime. However, the plugin files are still present on the harddisk.
    2. To remove the plugin files, close all Vim instances, open a new Vim window and invoke :UninstallNotLoadedAddons the_plugin_name

Notes

  • vim-addon-manager relies heavily on being able to handle inputs of paths and output paths to other tools it invokes. So, it breaks down if you have shellslash enabled in your vimrc. Remove any :set shellslash in your setup files.
  • I found that invoking scriptmanager#Activate() directly in vimrc at startup does not work. It only works properly if invoked after all the Vim setup is complete. Mark Weber suggests using the event GUIEnter to trigger scriptmanager#Activate(). I found that this breaks down since the input function does not work this early in the Vim startup. The VimEnter event seems to work fine for me, so I use it to trigger scriptmanager#Activate().
  • If you want to a simpler plugin to only manage each installed plugin in their subdirectory, check out Pathogen.

ViM: NetRW Plugin and Tree Style Listing

NetRW is an awesome plugin written by Charles Campbell that ships along with ViM. It is meant to be a file explorer for reading and writing network files, but works great for local files and directories too. ViM fans tend to recommend the NERD Tree plugin a lot, but I found that netrw satisfies all the file-explorer-like functionality I need. All the information you need to get started with netrw can be found in the VimCast here.

Tree Style Listing

netrw displays files in a flat hierarchy by default (left window in above screenshot). But, I like to have a tree view (right window in above screenshot). To setup netrw to show tree view by default, add this line to your vimrc:

let g:netrw_liststyle=3

For more info on this setting type :help g:netrw_liststyle in ViM.

ViM: Add or Update Plugins On The Fly

ViM does not have a robust way to install, update or uninstall plugins on the fly. So, typically ViM needs to be restarted to use new or updated plugins. However, most plugins are harmless and can be added or updated into a running ViM session. To do this invoke the command:

:runtime! plugin/*.vim

This command should be executed after the new plugin files have been placed into their destination plugin/ directory. It tries to execute all the ViM scripts in all the plugin/ directories present in the runtimepath. The commands and features exposed by the new plugin should be available inside a ViM session after executing this command.

For more info type :help runtime

ViM: MRU (Most Recently Used) Plugin

MRU (Most Recently Used) is a ViM plugin which I find uber useful. It keeps track of the most recently used files by ViM. To bring up the MRU file list type :MRU. It opens up a window at the bottom with the list, choose the file using Enter (keyboard) or double-click (mouse) and the file is loaded! :-)

Note: If you are loading this plugin through a plugin manager like vim-addon-manager, make sure the plugin name you use is mru (all lowercase). If you use MRU (all uppercase), there is another plugin named like that which will get loaded instead! :-)