- How to Easily Install Vim Plugins on Linux?
- Method 1: Install Vim Plugin Using Vim Plugin Manager
- Prerequisite: Install vim-plug Plugin Manager
- Install NERDTree Plugin Using vim-plug Manager
- Method 2: Manually Install Vim Plugin
- How to Update Installed Vim Plugins?
- How to Upgrade Installed Vim Plugins?
- How to Uninstall Vim Plugins?
- Conclusion
- How to Install the Vim Plugins
- Check the Vim Version
- Install the Vim Editor
- Set Vim
- Install Curl and Git
- Install the Vim Plugin Manager
- Install the Vim Plugins
- Conclusion
- About the author
- Omar Farooq
How to Easily Install Vim Plugins on Linux?
In Linux, the Vim editor is the most popular text editor with advanced features that include highly customizable and fast operations. To add more functionalities to the Vim editor, plugins are installed that add special features.
This guide will provide a practical guide to installing plugins with different methods.
- Method 1: Using Vim Plugin Manager
- Prerequisite: Install vim-plug Plugin Manager
- Install NERDTree Plugin Using vim-plug Manager
- Method 2: Manually Install Vim Plugin
- Update Installed Plugins
- Upgrade Installed Plugins
- Uninstall Vim Plugin
Method 1: Install Vim Plugin Using Vim Plugin Manager
To install the plugin using the vim plugin manager is quite easy; you need to follow the below steps. The vim-plug plugin manager is required to install the plugin in this method.
Prerequisite: Install vim-plug Plugin Manager
For installing the Vim plugin manager, run the below curl command:
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
The vim plugin manager is downloaded. Let’s install the plugin now.
Install NERDTree Plugin Using vim-plug Manager
To install the NERDTree plugin in Vim, follow the below easy steps:
Step 1: Create the .vimrc Configuration File
The plugin settings are saved in the “.vimrc” config file. When vim starts, it loads all the plugins available in the .vimrc file. Use the below-stated command to create and open the file in Vim:
The above interface for the .vimrc file will open.
Step 2: Add the Code for Specific Plugin
To add any plugin to Vim using the plugin manager, you must specify the plugin details within the begin() and end() codes. To add the NERDTree plugin in Linux, put the following code to the .vimrc file:
Note: If the plugin is already installed and you want to install another, you must add the plugin details in the code body below.
call plug#begin() Plug 'preservim/nerdtree' call plug#end()
The above code explanation is:
- call plug#begin(): It shows the plugin to be installed will be defined after this line.
- Body: Put the specific plugin “owner-name/plugin-name” here. The plugin owner’s name is “preservim”, and the plugin name is “nerdtree” which will be mentioned in the NERDTree plugin’s official git repository.
- call plug#end(): It shows that the plugins are declared in the body, and the plugin code ends here.
Note: The owner-name/plugin-name of any plugin is also mentioned in its official git link and as the tile of the plugin, as shown below:
Use the “:wq” command to save and exit vim.
Step 3: Install the Plugin
After adding the code to the “.vimrc” file, open the vim editor and use the below command to install the plugin defined in the .vimrc file:
The output shows the “Finishing… Done!” status that the plugin is installed successfully.
Step 4: Verify the Installed Plugin
To verify that the NERDTree plugin is successfully installed in Vim, run the below command to list the plugins installed in Linux:
It shows that the “NERDTRee” plugin is installed in Vim.
Method 2: Manually Install Vim Plugin
Let’s manually install the “rust-vim” plugin in Vim by performing some easy steps.
Step 1: Create Default Directory for Specific Vim Plugin
To install any plugin manually, you must create its default directory first. To create the default directory, its general syntax is as follows:
$ mkdir -p ~/.vim/pack/vendor/start
The “mkdir” command will create a directory and the “p” flag will detect if the directory already exists (and avoids the creation).
To create the default directory for the plugin “vim-airline”, run this command in the terminal:
$ mkdir -p ~/.vim/pack/vendor/start
The default directory for the vim-airline plugin is created manually.
Step 2: Change the Directory to Default Plugins Directory
Use the below cd command to change the directory to the default manual plugins directory:
Step 3: Clone the Official HTTPS Address for the Specific Plugin
Now, we need to clone the vim-airline HTTPS address to the default directory using the following command:
Note: Replace with the plugin’s specified HTTPS address and git clone command.
$ git clone https://github.com/vim-airline/vim-airline.git
The Vim plugin is cloned to the default plugin directory.
Step 4: Verify the Installed Plugin
Use the below command to verify that the “vim-airline” plugin is successfully installed:
The output shows that the vim-airline plugin is successfully installed.
How to Update Installed Vim Plugins?
If the plugins are already installed, and you want to update all the plugins, execute the following command:
To update multiple plugins in Vim, write the plugin names with the PlugInstall command as shown below and run the command in Vim:
:PlugInstall plugin1 plugin2
How to Upgrade Installed Vim Plugins?
In the previous steps, we updated all plugins and a single plugin. While to upgrade the updated plugins, run the below-stated command in Vim:
How to Uninstall Vim Plugins?
To remove the plugin, navigate to the “.vim” file with the below-mentioned command and remove the specific plugin line:
After removing that highlighted line, the NERDTree plugin will be deleted.
Conclusion
There are two methods to install the plugins in Vim, using the vim plugin manager and manually installing the plugin. Install the Vim plugin manager and add the “owner-name/plugin-name” to the “.vimrc” file. To install the plugin using the manual method, we can create the directory and make a clone of the official plugin git link to that directory.
This guide has elaborated on these methods alongside the update/upgrade techniques.
How to Install the Vim Plugins
A text editor that is frequently used in the command-line situations is called Vim (Vi Improved). It is renowned for its effective keyboard shortcut implementation and simultaneous usage of several documents. A Vim plugin is a collection of Vim scripts that add a functionality to the text editor. These scripts can offer many features like syntax highlighting, new commands, and file type compatibility. Vim plugins are typically distributed as a package and can be easily installed and managed using a plugin manager. With numerous plugins available for added functionality, Vim is a text editor that is extremely adjustable and adaptable. In this guide, we will show you a method to install the Vim plugins in Linux.
Check the Vim Version
First, we take a look at the version command to get the version of a “Vim” editor installed. If the command shows the output like the one in the following, it means that your system has no “Vim” editor installed. Also, it gives you some command suggestions for its installation.
omar@virtualbox:~$ vim —version
Command ‘vim’ not found, but can be installed with:
sudo apt install vim # version 2:8.2.3995-1ubuntu2.3, or
sudo apt install vim-tiny # version 2:8.2.3995-1ubuntu2.3
Just like that, if you try to open some file with “vim”, it won’t allow you and shows you the following output along with some command suggestions like “vim not found”:
omar@virtualbox:~$ vim pass.txt
Command ‘vim’ not found, but can be installed with:
sudo apt install vim # version 2:8.2.3995-1ubuntu2.3, or
sudo apt install vim-tiny # version 2:8.2.3995-1ubuntu2.3
Install the Vim Editor
To get Vim in your Linux system, you have to try using the following-attached command using the apt package manager. The system downloads two packages, “vim” and “vim-runtime”, which are both new to the system. The command prompts the user to confirm the installation by typing “y” and hitting enter. Vim editor is installed in less than 10 seconds.
Set Vim
To set the Vim editor according to your needs, you can use its configuration file which is vimrc. To open the vimrc file, we use the “nano” editor with sudo rights. After adding some commands to it, we save it and open it once again to reflect the changes.
Install Curl and Git
It’s necessary to install curl and Git in your Linux system before installing the Vim plugins. Therefore, we use the apt-get instruction with the “install” keyword followed by the package name. The command is executed and both the packages are installed smoothly.
Install the Vim Plugin Manager
Here, we create two directories, “autoload” and “bundle”, within a directory called “.vim” in the user’s home directory. The “mkdir” command is used to create the directories. The “-p” option tells the command to create any parent directories in the path if they do not already exist. After this, you need to move within the bundle folder of Vim using the following “cd” instruction:
omar@virtualbox:~$ mkdir -p ~ / .vim / autoload ~ / .vim / bundle
omar@virtualbox:~$ cd ~ / .vim / bundle
omar @ virtualbox:~ / .vim / bundle$
There are several ways to install Vim plugins, but one of the most popular methods is to use a plugin manager i.e. tool that makes it easy to install, update, and manage Vim plugins. The “curl” command is installing a Vim plugin manager called “vim-plug”. Option -f tells curl to fail silently if the HTTP server returns an error code, -L tells the curl to follow any redirections, -o tells curl to save the output to a file named “~/.vim/autoload/plug.vim”. and –create-dirs tells curl to create the directories specified in the -o option if they don’t exist. The file being downloaded will be saved in the “~/.vim/autoload” directory. Once the command is executed successfully, the vim-plug is installed and ready to use in Vim.
omar@virtualbox:~/.vim/bundle$ curl -fLo ~ / .vim / autoload / plug.vim —create-dirs https: // raw.githubusercontent.com / junegunn / vim-plug / master / plug.vim
Install the Vim Plugins
The manual way of installing the Vim plugins is to use the simple Git command to clone the official package of the repository. Let’s say, we want to install the nerdtree Vim plugin and use the Git clone command followed by the directory where the repository should be cloned. The progress shows that the repository is cloned into the specified directory. The result displays the repository’s download status and download speed. Once the command is executed successfully, the nerdtree plugin is installed and is ready to use in Vim.
omar@virtualbox:~/.vim/bundle$ git clone https: // github.com / preservim / nerdtree.git / ~ / .vim / pack / vendor / start / nerdtree
The other way to install the Vim plugins is to use the Vim plugin manager, “vim-plug”, via the Vim configuration file, “vimrc”. This is a configuration code for Vim’s plugin manager that is used to install and manage the plugins for Vim. Open the vimrc file and write the following code in it. The code starts by calling the “plug#begin()” function. Start the configuration of the plugins that are managed by the vim-plug. After that, the code uses the “Plug” command followed by the name of the plugin which is “preservim/NERDTree”. This command tells the vim-plug to install the plugin from the specified “preservim/NERDTree” repository. Finally, the code calls the “plug#end()” function to end the configuration of the plugins that are managed by the vim-plug and it should proceed with the installation of the specified plugins. After this code is executed, the NERDTree plugin is installed and is ready to use in Vim.
There is a command that is used to install the plugins that are specified in the vim-plug configuration. The “:PlugInstall” command tells the vim-plug to install any plugins that are specified in the configuration but have not yet been installed. Use this command in the “insert” mode of the Vimrc file. It downloads the plugin from their repository. After this, it installs the Nerdtree plugin and makes it ready to use in Vim.
The installation process is displayed at the right panel of the vimrc file after executing the “:PlugInstall” instruction as shown in the attached image where the NERDTree plugin is installed:
If you want to update the already installed plugin of Vim, use the “PlugUpdate” instruction in the insert mode of Vim followed by the name of a plugin as shown in the following:
The output shows that the NERDTree plugin is already up-to-date.
Conclusion
We explained the use of Vim editor and its plugins within the introduction. Also, this guide is the bundle of commands to install the Vim plugins using two different methods: using the Git clone instruction and the vim-plug plugin manager. Using both ways, we demonstrated how a Vim plugin like NERDTree can be installed in the Linux system.
About the author
Omar Farooq
Hello Readers, I am Omar and I have been writing technical articles from last decade. You can check out my writing pieces.