Linux Format

TERMINAL: Extending Vim

Being quite versatile himself, it’s no wonder Shashank Sharma has such fondness for the highly extendable Vim.

- Shashank Sharma is a trial lawyer in Delhi. He’s pained at having to abandon the noble quest of growing a yeard.

Being quite versatile himself, its no wonder Shashank Sharma has such fondness for the highly extensible Vim and he’s going to make it even better!

Back in LXF258 we introduced you to Vim, a fiercely popular and featureful text editor, and discussed how you can enhance your Vim experience by enabling some advanced options such as auto-completion, smart search, and even polish your writings by using a thesaurus and dictionary.

While all that can be done with a vanilla Vim installati­on, albeit with some modificati­ons to the configurat­ion file, with different plugins you can get additional useful features such as creating bullet lists, and can even transform Vim into a password manager, and more.

Before we do that, however, it’s imperative to learn how to install plugins. The easiest way is to download the individual files into a dedicated directory, and update the ~/.vimrc file. The downside to this approach is that you have to manually install updates for each of the plugins as they become available. This is still not a problem if all you have is half a dozen plugins, but what if you had more? There are dozens and dozens of plugins that you may wish to use at one time or another, and manually fetching each is unnecessar­ily painful. You can instead use a plugin manager, which makes installing, updating, and deleting plugins a breeze.

Using Vim-plug

Our favourite plugin manager is vim-plug, which is quite straightfo­rward to set up and use. To begin, open a terminal and run the curl -o ~/.vim/autoload/plug.vim https://raw.githubuser­content.com/junegunn/vimplug/master/plug.vim command. If you already have a ~/.vim/autoload directory, you can alternativ­ely navigate into this directory and download the plug.vim

file with the wget https://raw.githubuser­content.com/ june gunn/ vim-plug/ master/ plug. vim

The next step is to inform Vim to use vim-plug plugin manager. You need to edit the ~/.vimrc file and add the following lines: call plug# begin (‘~/. vim/ plugin s-place holder ’) call plug#end()

Leave the rest of the ~/.vimrc file unchanged for now. In the first line, you must provide the complete path to a directory where Vim-plug will store all the downloaded plugins. The project suggests using any name for this

directory, except standard Vim directory names like ‘plugins’. The single quote is also part of the line, so make sure to type it along with the path name.

Normally we would advise you to use any text editor to edit configurat­ion files, but in this instance it makes sense to make the changes using Vim. After making the changes to ~/.vimrc file, save the file by pressing Esc and typing :w . Now, while Vim is still running, press Esc again, and type :source % . This reloads the ~/.vimrc file so that vim knows to use the vim-plug plugin manager now. The % symbol is used to tell Vim to use the current file. You can alternativ­ely type the complete path with the source ~/.vimrc command.

You can now declare each of the plugins you wish to use in the ~/.vimrc file. The declaratio­n is in the format Plug ‘foo/bar’. The code below shows how you can invoke the bullet list plugin:

#Lines beginning with a # are comments #Plugins are mentioned between the call plug#begin line and the call plug#end() line call plug#begin(‘~/.vim/plugins-placeholde­r ‘) Plug ‘dkarter/bullets.vim’ call plug#end()

You can declare many different plugins in the

~/.vimrc file. In the code above, since the bullets plugin is hosted on Github, we’ve used shorthand notation to identify the plugin we wish to use. You can alternativ­ely also provide the complete path to the Git repository:

call plug#begin(‘~/.vim/plugins-placeholde­r’) Plug ‘https://github.com/dkarter/bullets.vim.git’ Plug ‘reedes/vim-lexical’

Plug ‘reedes/vim-pencil’

Plug ‘antenore/vim-safe’ call plug#end()

From inside Vim, run the :Plugstatus command and hit Enter. You’ll see a list of currently installed and available plugins. Don’t worry if none show up when you run it for the first time. With all the plugins you wish to use invoked in the ~/.vimrc file, run the :Pluginstal­l

command from within Vim. This automatica­lly downloads and installs the plugins mentioned in the

~/.vimrc file. When you run the command, Vim displays the installati­on status for each command on the left pane of the screen, while the right pane displays the ~/.vimrc file. Hit q to return to editing the ~/.vimrc file.

You can check the status of the installed plugins by running the :Plugstatus command from within Vim or by navigating to your plugins directory. All installed plugins will get populated in the directory specified in the call plug#begin line of the ~/.vimrc file.

Updating and removing plugins

A major advantage of using plugin managers such as vim-plug is that you don’t have to chase after updates for each of your different plugins. A single command can be used to update all the plugins at once.

From within Vim run the :Plugupdate command, and vim-plug will fetch and install updates where available. Run the :Plugdiff command to inspect the changes made to each of the plugins by their respective updates.

To delete a plugin, you can either comment out the relevant Plug command in the ~/.vimrc file, or delete it entirely. Next, source the ~/.vimrc file again with the :source % command, and finally run the :Plugclean command. You’ll be prompted to confirm if you wish to delete the plugins. If you don’t want to be prompted for a confirmati­on and instead want the plugins to be purged straight away, you will need to run the :Plugclean! command.

A shortcomin­g of the vim-plug plugin manager is that it can’t resolve dependenci­es. This means that you have to also declare each of the plugins that a plugin might depend on in order to provide all of the functional­ity.

Zen masters and command-line ninjas such as this author have a lot in common. Our task is just to show you the path. It’s for each young Padawan to decide to take the journey on their own. Perhaps the author has spent too much time immersed in pop culture to make sense, but you will have to decide for yourself which plugins to use, depending on the features you want most in your text editor

 ??  ?? Vundle and Pathogen are also quite popular plugin managers for Vim, and work much the same way as vim-plug.
Vundle and Pathogen are also quite popular plugin managers for Vim, and work much the same way as vim-plug.
 ??  ??
 ??  ?? As with most command-line utilities, the different commands, such as :Pluginstal­l etc. are case sensitive.
As with most command-line utilities, the different commands, such as :Pluginstal­l etc. are case sensitive.

Newspapers in English

Newspapers from Australia