Reader small image

You're reading from  Mastering Vim

Product typeBook
Published inNov 2018
PublisherPackt
ISBN-139781789341096
Edition1st Edition
Tools
Right arrow
Author (1)
Ruslan Osipov
Ruslan Osipov
author image
Ruslan Osipov

Ruslan Osipov is a software engineer at Google, an avid traveler, and a part-time blogger. He is a self-taught engineer. He started publishing personal Vim notes in 2012, and became increasingly interested in the intricacies of the editor and its applications in optimizing development workflows.
Read more about Ruslan Osipov

Right arrow

Follow the Leader - Plugin Management

Vim plugins are easy to make and the number of available plugins keeps growing every year. Some cater to a very narrow audience and improve on a very particular workflow, while others aim to make Vim more effective to use for the general public. This chapter will take a deep dive into installing plugins and customizing your workflow through remapping keys. This chapter will cover the following topics:

  • Ways to manage multiple plugins with vim-plug, Vundle, Pathogen, or a home-made solution
  • A way to profile slow plugins
  • An in-depth explanation of primary modes in Vim
  • Intricacies of remapping commands
  • The leader key and how it's useful for all kinds of custom shortcuts
  • Configuring and customizing plugins

Technical requirements

Managing plugins

You have already installed quite a few plugins so far, and the number will only keep going up, especially as you try to solve problems that are specific to whatever it is you're working on. Manually keeping plugins up to date requires quite a bit of work, but luckily there are plugin management solutions out there!

Plugin management becomes even more important if you often change or switch machines and have the need to keep multiple plugins updated.

For more tips on keeping Vim synced between multiple machines, see Chapter 7, Making Vim Your Own.

The plugin management landscape is ever changing, and there's no substitute for good old research when choosing a plugin manager. This chapter covers a few plugin managers that I've used throughout the years, which will hopefully be enough for you to base your own research on.

...

Deeper dive into modes

You've already encountered a few different modes Vim operates in, and this section will cover these and the remaining modes in depth. As you have already learned, Vim uses modes to know how to respond to input: a key press in normal mode will produce different results from a key press in insert or command-line mode.

Vim has seven primary modes, and it's important to understand what each mode does in order to comfortably navigate Vim.

Normal mode

This is where you will (and already have) spend most of your time with Vim. You enter normal mode by default when opening Vim, and you can go back to normal mode from other modes by pressing the Esc key (sometimes twice).

...

Remapping commands

Now that you are comfortable working with plugins, you may want to consider customizing your Vim further by remapping commands to suit your preferences. Plugins are written by many kinds of different people, and everyone's workflow is different. Vim is infinitely extensible, allowing you to remap nearly every action, change certain default behaviors, and really make Vim your own. Let's talk about remapping commands.

Vim allows you to remap certain keys to be used in place of other keys. :map and :noremap provide just that:

  • :map is used for recursive mapping
  • :noremap is used for non-recursive mapping

This means that commands remapped with :map are aware of other custom mappings, while :noremap works with system defaults.

Before you decide to create a new mapping, you may want to see whether the key or sequence you're mapping to is already used...

The leader key

You've probably already encountered a key referred to as the leader key. The leader key is essentially a namespace for user or plugin defined shortcuts. Within a second of pressing the leader key, any key that's pressed will be in from that namespace.

The default leader key is a backslash \, but it's not the most comfortable binding. There are a few alternative keys that are popular in the community, with the comma (,) being the most popular. To rebind the leader key, set the following in your .vimrc file:

" Map the leader key to a comma.
let mapleader = ','

You'll want to define your leader key closer to the top of .vimrc, as the newly defined leader key will only apply to mappings defined after its definition.

When you rebind a key, it's default functionality is overwritten. For example, comma , this is used to replay the...

Configuring plugins

Plugins often expose commands for you to map to and variables to change plugin behavior. It's a good idea to review the available options and commands for the plugins you use. Sane plugin defaults make a huge difference in experience. Creating shortcuts that are easy for you to remember will help you remember how to use the plugin you forgot about in a few months.

Vim allows for the creation of global variables, which are primarily used to configure plugins. Global variables are usually prefixed by g:. You can find a list of configuration options in the plugin documentation by running :help <plugin-name> and looking for options.

For example, opening a help file for the CtrlP plugin (by running :help ctrlp) and searching for options (/options) yields the following:

You can read more about the CtrlP plugin under Chapter 2, Advanced Editing and Navigation...

Summary

In this chapter, we've talked about the different ways of managing plugins. The new shiny thing is vim-plug, a lightweight plugin manager that can asynchronously install and update your plugins. Vundle, its predecessor, also allows you to search for and temporarily install new plugins. We've also learned how to manually work with plugins: Vim 8.0 introduced a way to load plugins without the need to manually alter runtimepath for each plugin. If you still use Vim below version 8, then Pathogen provides a way to automate some of the runtimepath manipulation.

We've looked at profiling Vim with a --startuptime flag and the :profile command.

We've revisited modes, covering every major mode: normal mode, command-line and ex modes, insert mode, visual and select modes, and terminal mode.

We've talked about remapping commands to make Vim truly yours. Different...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Vim
Published in: Nov 2018Publisher: PacktISBN-13: 9781789341096
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ruslan Osipov

Ruslan Osipov is a software engineer at Google, an avid traveler, and a part-time blogger. He is a self-taught engineer. He started publishing personal Vim notes in 2012, and became increasingly interested in the intricacies of the editor and its applications in optimizing development workflows.
Read more about Ruslan Osipov