Skip to content

Vim - Plug-ins

Vim - Extending Functionality with Plugins

Section titled “Vim - Extending Functionality with Plugins”

Plugins are scripts that extend Vim’s built-in features or add entirely new capabilities. The Vim community has created a vast ecosystem of plugins for everything from syntax highlighting and code completion to Git integration and project management. Modern Vim (version 8+) includes a native package management system that simplifies plugin handling.

This chapter covers:

  • Understanding Vim’s native package management.
  • Installing, updating, and removing plugins.
  • Examples of useful plugin categories.

Vim’s Native Package Management (Vim 8+)

Section titled “Vim’s Native Package Management (Vim 8+)”

Since Vim 8, there’s built-in support for loading plugins from specific directory structures, eliminating the need for older plugin managers like Pathogen for basic use cases. This system relies on the packpath option (which usually includes ~/.vim on Linux/macOS or ~/vimfiles on Windows).

Plugins are organized into ‘packages’. A package is simply a directory containing one or more plugins. The standard structure is:

~/.vim/pack/{package_name}/start/{plugin_name}/
~/.vim/pack/{package_name}/opt/{plugin_name}/
  • {package_name}: A name you choose for a collection of plugins (e.g., common, colors, myplugins).
  • start: Plugins in a start subdirectory are loaded automatically when Vim starts.
  • opt: Plugins in an opt subdirectory are optional and can be loaded manually using the :packadd {plugin_name} command.
  • {plugin_name}: The directory containing the actual plugin files (e.g., nerdtree, vim-airline).

For Windows, replace ~/.vim/ with ~/vimfiles/ (e.g., C:\Users\YourName\vimfiles\pack\...).

Let’s install the badwolf colorscheme plugin as an example. We’ll put it in a package named colorschemes.

  1. Create the directory structure (if it doesn’t exist):
  2. On Linux/macOS:
  3. $ mkdir -p ~/.vim/pack/colorschemes/start
  4. On Windows (using Command Prompt):
  5. C:\> mkdir "%USERPROFILE%\vimfiles\pack\colorschemes\start"
  6. Clone the plugin repository into the start directory: Most Vim plugins are hosted on Git repositories like GitHub.
  7. $ cd ~/.vim/pack/colorschemes/start/
    

$ git clone https://github.com/sjl/badwolf.git 8. (This creates ~/.vim/pack/colorschemes/start/badwolf/)

That’s it! Because it’s in a start directory, Vim will automatically load it. You can now use the colorscheme:

:colorscheme badwolf

You don’t need to modify your vimrc’s runtimepath for plugins installed this way.

If a plugin was installed using Git, updating is straightforward. Navigate to the plugin’s directory and pull the latest changes:

$ cd ~/.vim/pack/colorschemes/start/badwolf
$ git pull

To remove a plugin, simply delete its directory:

$ rm -rf ~/.vim/pack/colorschemes/start/badwolf

While native package management is great, dedicated plugin managers like vim-plug, Vundle, or dein.vim offer more advanced features like easier plugin listing in vimrc, conditional loading, lazy loading, and streamlined update/removal commands. They typically manage plugins by cloning them into a single directory (e.g., ~/.vim/plugged/) and automatically managing the runtimepath.

If you plan to use many plugins or need sophisticated management, exploring a plugin manager is recommended. However, for a few plugins, the native system is often sufficient.

The world of Vim plugins is vast. Here are some common categories and examples to give you an idea:

  • File Explorers: For navigating your project’s file system.
    • NERDTree: A popular tree explorer.
    • netrw: Vim’s built-in file explorer (enable with :edit . or :Explore).
  • Fuzzy Finders: For quickly finding files, buffers, or text.
    • fzf.vim (requires fzf external tool): Extremely fast and versatile.
    • CtrlP: Another popular choice.
  • Status Lines & Appearance: Enhance Vim’s status line and overall look.
    • vim-airline, lightline.vim: Powerful status line customizers.
    • Countless colorscheme plugins (like badwolf shown above).
  • Git Integration: Work with Git repositories without leaving Vim.
    • fugitive.vim: A comprehensive Git wrapper.
  • Code Completion & Language Support (LSP):
    • For advanced autocompletion, linting, and language-specific features, Language Server Protocol (LSP) clients are common.
    • coc.nvim: A powerful LSP client (works in Vim and Neovim).
    • Simpler completion plugins like vim-mucomplete or language-specific plugins exist.
  • Snippets: Insert common code blocks quickly.
    • ultisnips (requires Python), neosnippet.vim.

Practical Application: Plugins transform Vim from a powerful text editor into a tailored development environment. For example, a web developer might install plugins for HTML/CSS/JavaScript syntax, autocompletion, a file explorer, and Git integration to streamline their workflow.